我正在使用 Angular-UI 时间插件,因此我需要将简单的时间格式转换为更复杂的时间格式,即
来自:
16:19:29
至:
Wed Dec 09 2015 16:09:15 GMT+0530 (India Standard Time)
或者如果可能的话,使用此格式的完整数据:
"2015-12-17 16:19:29"
我从 json 收到的。
我需要知道是否存在将简单时间格式转换为扩展形式的 JavaScript 函数(日月年不重要,我可以处理!)
最佳答案
尝试这个演示
<html>
<head>
<title>Please Rate if it helps</title>
<script>
Date.prototype.myFormat = function (start) {
var temporeryDay = this.getDate();
var temporeryMonth = this.getMonth() + 1;
var temporeryYear = this.getFullYear();
var temporeryHours = this.getHours();
var temporeryMinutes = this.getMinutes();
var temporerySeconds = this.getSeconds();
temporeryDay = temporeryDay.toString().length == 1 ? "0" + temporeryDay.toString() : temporeryDay.toString();
temporeryMonth = temporeryMonth.toString().length == 1 ? "0" + temporeryMonth.toString() : temporeryMonth.toString();
temporeryHours = temporeryHours.toString().length == 1 ? "0" + temporeryHours.toString() : temporeryHours.toString();
temporeryMinutes = temporeryMinutes.toString().length == 1 ? "0" + temporeryMinutes.toString() : temporeryMinutes.toString();
temporeryHours = temporeryHours.toString().length == 1 ? "0" + temporeryHours.toString() : temporeryHours.toString();
temporerySeconds = temporerySeconds.toString().length == 1 ? "0" + temporerySeconds.toString() : temporerySeconds.toString();
return (temporeryYear + "-" + temporeryMonth + "-" + temporeryDay + " " + temporeryHours + ":" + temporeryMinutes + ":" + temporerySeconds);
}
window.onload = function () {
document.write(new Date().myFormat());
}
</script>
</head>
<body>
</body>
</html>
关于javascript - 从 hh :mm:yy (24 hour) to expanded time form 开始的时间转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34177018/