Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

javascript - 使用Javascript的当前时间格式(Current time formatting with Javascript)

I want to get current time in a specific format with javascript.(我想用javascript获取特定格式的当前时间。)

With the function below and calling it will give me Fri Feb 01 2013 13:56:40 GMT+1300 (New Zealand Daylight Time) but I want to format it like Friday 2:00pm 1 Feb 2013(使用下面的函数并调用它,它将给我星期五Feb 01 2013 13:56:40 GMT + 1300(新西兰夏令时间),但我想将其格式化为2013年2月1日星期五2:00 pm) var d = new Date(); var x = document.getElementById("time"); x.innerHTML = d; Of course, code above doesn't have any formatting logic but I have not come across with any "working" formatters yet.(当然,上面的代码没有任何格式化逻辑,但是我还没有遇到任何“有效的”格式化程序。)   ask by Seong Lee translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You may want to try(您可能要尝试)

var d = new Date(); d.toLocaleString(); // -> "2/1/2013 7:37:08 AM" d.toLocaleDateString(); // -> "2/1/2013" d.toLocaleTimeString(); // -> "7:38:05 AM" Documentation(文献资料)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...