将时间hh:mm:ss转换为Angular 2中的GMT时间格式 [英] Convert time hh:mm:ss into GMT time format in Angular 2

查看:109
本文介绍了将时间hh:mm:ss转换为Angular 2中的GMT时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入:-

时间:21:00:00

time: 21:00:00

输出应为:-

时间:2017年12月20日星期三21:00:00 GMT + 0530(IST)

time: Wed Dec 20 2017 21:00:00 GMT+0530 (IST)

OR

时间:2017-12-20 21:00:00

time: 2017-12-20 21:00:00

推荐答案

您的输入是: 21:00:00

使用以下JS代码通过':'分割输入内容:

Split your input by ':' using JS code below:

let timeArr = "21:00:00".split(':');

然后,使用新的日期功能将日期添加到时间,即

then, use new date function to add date to the time i.e,

let newDateTime = new Date().setHours(timeArr[0], timeArr[1],0,0);

然后您可以将时间转换为

then you can convert your time to,

let finalDate = new Date(newDateTime);

,您将获得finalDate = 2017年12月20日,星期三21:00:00 GMT + 0530(IST)

这篇关于将时间hh:mm:ss转换为Angular 2中的GMT时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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