且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在javascript中将(M:d:yy hh:mm:ss tt)格式的字符串转换为(MM / dd / yy hh:mm:ss tt)格式

更新时间:2023-11-07 18:29:52

检查这个jsfiddle: b $ b

转换日期时间 - JSFiddle [ ^ ]


第一行是字符串格式的日期。

第二行是日期对象的实例(变量)。字符串到日期格式转换在此处完成。当然,您可以使用解析方法进行转换,但这种方法更好更清洁。

第三行在弹出框中显示日期格式。



我希望这会有所帮助。






我已经尝试过这段代码我希望你能理解。

如果你将日期时间值存储到字符串str中并将其作为参数传递给Date对象,如下所示:



  var  str =   09/02/2016 14:00:00; 
var todate = new 日期(STR);
window .alert(todate);





你可以做任何你想要的回报,在这种情况下todate。



问候



hubsnippet

Daystarter


Can some one help me with this ?
How to Convert a string that is in (M: d:yy hh:mm:ss tt) format to (MM/dd/yy hh:mm:ss tt) format in javascript without using moment.js

What I have tried:

tried using many alternatives .. but couldn't get any results.. can someone help me soon ?

Check this jsfiddle:

convert date time - JSFiddle[^]


The first line is the date in string format.
The second line is an instance (a variable) of date object. The string to date format conversion is done here. Naturally, you'd do conversion with the parse method, but this approach is better and cleaner.
The third line displays the date format in a pop-up box.

I hope this helps.


Hi,

I've tried out this code and I hope you'd understand.
If you store the datetime value into a string str and pass it as argument to the Date object like below:

var str = "09/02/2016 14:00:00";
var todate = new Date(str);
window.alert(todate);



You can do whatever you wish to the value returned, in this case "todate".

Regards

hubsnippet
Daystarter