Javascript日期处理自定义值 [英] Javascript Date Handling for Custom Value
问题描述
日期需要格式化,即使价值与格式不完全匹配,
Date need to be formatted even value is not exactly matching with the format,
Value Actual Format
01/10/2015 dd/MM/yyyy HH:mm:ss
05/08/2016 dd/MM/yyyy HH:mm
07/06/2014 00:00 dd/MM/yyyy HH:mm:ss
24/12/2013 dd/MM/yyyy h:mm:ss tt
预期结果
01/10/2015 00:00:00
05/08/2016 00:00
07/06/2014 00:00:00
24/12/2013 0:00:00 AM
格式是基于用户固定的,但用户可能输入部分值,这种情况我需要填写
Format is fixed based on user, But user may enter partial value that case I need to fill it
我尝试了很多东西,但是没有运气。有人可以尝试吗?
I tried many things, but no luck. Can someone give a try?
推荐答案
最简单的Javascript可能是使用日期构造函数。
The most plain Javascript possible is using the Date constructor.
你可以漂亮将所有东西都放入其中,并通过提供的吸气器再次获得需要的部件。
如果信息丢失,就像说时间一样,它们都是0.但是您可以轻松添加当前时间(例如,查看更多)。
You can pretty much throw everything into it and get the parts you need out again through the provided getters. In case information is missing, like say the time, they are all 0. But you can easily add the current time for example (see the setters for more).
如果这还不满足你的话,也有JS库。
If this still does not satisfy you, there are JS libraries too.
这篇关于Javascript日期处理自定义值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!