我正在使用 Javascript 和 Date.js,并且需要翻译时间的字符串表示形式。
我从这种格式的时间开始:
3:00am 2:30pm 11:00am
...and need to put them in this format:
03:00:00 14:00:00 11:00:00
I was thinking of starting with Date.parse() and then printing out the hours, minutes, and seconds. But was wondering if there is a more elegant way to do this such as something along the lines of Date.format("HH:MM:SS")
What is a good way to do this?
Thanks!
Edit::::
It looks like you can use the format specifiers with Date.js: http://code.google.com/p/datejs/wiki/FormatSpecifiers
Date.parse("3:00am").toString("HH:mm:ss");
最佳答案
The answer to all your questions
<script type="text/javascript">
<!--
var d = new Date();
var curr_hour = d.getHours();
var curr_min = d.getMinutes();
var curr_sec = d.getSeconds();
document.write(curr_hour + ":" + curr_min + ":" + curr_sec);
//-->
</script>
关于Javascript以特定格式写入时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6657855/