如何在javascript中将20-11-2015转换为20-11-2015 12:34:59 [英] How to Convert 20-11-2015 to 20-11-2015 12:34:59 in javascript
本文介绍了如何在javascript中将20-11-2015转换为20-11-2015 12:34:59的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只有约会。
expdate =20-11-2015
I想把这个日期转换成20-11-2015 12:34:59
我试过
var ab = Date.parse(expdate);
但它不起作用。
I have only date.
expdate = "20-11-2015"
I want to convert this date to 20-11-2015 12:34:59
I tried
var ab = Date.parse(expdate );
but its not working.
推荐答案
Date构造函数或Date.parse中日期字符串的预期格式遵循以下格式:YYYY-MM-DDTHH:mm :ss.sssZ
支持其他格式,但可能会产生意外结果。
参见 15。15。15。15日期时间字符串格式 [ ^ ]
在您的示例中,应该是2015-11-20,时间部分不包括在内。
时间部分是隐式假设的,你的日期字符串将被解释为'2015-11-20T00:00:00.000'
但是,正如评论中所述你永远不会期望从日期字符串中获取时间。
你在服务器端使用的代码
The expected format for a date string in the Date constructor or Date.parse follows this format: YYYY-MM-DDTHH:mm:ss.sssZ
Other formats are supported, but might give unexpected results.
See 15.9.1.15 Date Time String Format[^]
In your example that should be '2015-11-20', the time part not included.
The time part is implicitly assumed and your date string will be interpreted as '2015-11-20T00:00:00.000'
However, as have been stated in the comment section, you can never expect to get the time from a date string alone.
The code you are using on the server side
DateTime expiredate = DateTime.Now;
将为您提供完整的日期和时间,包括时区。
那么你如何选择为用户呈现日期和时间是另一回事。
你在JS中的选择是有限的,并且通常依赖于本地化。
这是一个开始使用的地方 JavaScript日期 [ ^ ]
这篇关于如何在javascript中将20-11-2015转换为20-11-2015 12:34:59的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文