如何在javascript中将(M:d:yy hh:mm:ss tt)格式的字符串转换为(MM / dd / yy hh:mm:ss tt)格式 [英] 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

查看:201
本文介绍了如何在javascript中将(M:d:yy hh:mm:ss tt)格式的字符串转换为(MM / dd / yy hh:mm:ss tt)格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我吗?

如何将(M:d:yy hh:mm:ss tt)格式的字符串转换为(MM / dd / yy hh: mm:ss tt)javascript中的格式,不使用moment.js



我尝试过:



尝试使用很多替代品..但无法得到任何结果..有人可以帮助我吗?

解决方案

检查这个jsfiddle:< br $> b $ b

转换日期时间 - JSFiddle [ ^ ]


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

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

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



我希望这会有所帮助。






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

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



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





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



问候



< a href =http://hubsnippet.in> 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


这篇关于如何在javascript中将(M:d:yy hh:mm:ss tt)格式的字符串转换为(MM / dd / yy hh:mm:ss tt)格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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