javascript - 从 hh :mm:yy (24 hour) to expanded time form 开始的时间转换

标签 javascript angularjs angular-ui-bootstrap

我正在使用 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/

相关文章:

javascript - 井字游戏 JavaScript

javascript - 不使用id提交

javascript - Node.JS HTTPS 问题 TypeError : Cannot read property 'writeQueueSize' of null

javascript - AngularJS - 如何在链接函数中获取独立的指令范围变量?

angularjs - 使用 Angular Controller 中的预定义值设置 ons-switch

c# - 在 ASP.NET 中自动刷新网页并捕获时间直到下一次刷新

javascript - 从外部 Controller 调用 Angular JS

javascript - 将数据从表单返回给 Controller

javascript - 从外部按钮清除 Angular Bootstrap UI 选项卡集中与文本区域关联的 ng-model

javascript - 限制输入结果