如何将日期转换为HTML中的单词 [英] How to convert date to words in HTML

查看:154
本文介绍了如何将日期转换为HTML中的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期以HTML显示。日期目前显示为 2012-03-12 。所以现在,我想把这个日期显示为一个字,即应该显示为$ code> 2012年3月12日。以下是我使用的HTML代码。

 < tr> 
< th>出生日期:< / th>
< td> {{dob}}< / td>
< / tr>

这里, dob 包含被转换为单词。我该怎么做?

解决方案

如果您的日期是 Date 的实例,那么您可以尝试这样的事情

  var dob = new Date('3/12/2012'); 
var dobArr = dob.toDateString()。split('');
var dobFormat = dobArr [2] +''+ dobArr [1] +''+ dobArr [3];

这将使 dobFormat 2012年3月12日
(如果您想要说 3月与Rhyono建议的情况相符)。


I have a date displayed in HTML. The date is currently displayed as 2012-03-12. So now, I want to display this date as words i.e it should be displayed as 12 March 2012. Below is the HTML code I used.

<tr>
  <th>Date of Birth: </th>
  <td>{{dob}}</td>
</tr>  

Here, dob contains the value that has to be converted to words. How can I do this?

解决方案

If your date is an instance of Datethen you can try something like this

var dob = new Date('3/12/2012');
var dobArr = dob.toDateString().split(' ');
var dobFormat = dobArr[2] + ' ' + dobArr[1] + ' ' + dobArr[3];

This would make dobFormat 12 Mar 2012 (if you want it to say March couple this with what Rhyono has suggested).

这篇关于如何将日期转换为HTML中的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆