简体   繁体   English

在UTC中转换日期时间

[英]Convert date time in utc

i have to convert date in utc from locale date time in birt. 我必须从birt的语言环境日期时间转换utc中的日期。 The only problem is that the date is divide in two numeric data type like '20131012' instead for 'yyyyMMdd' and '223112'instead for 'h24:mi:ss'. 唯一的问题是日期被分为两个数字数据类型,例如“ 20131012”,而不是“ yyyyMMdd”和“ 223112”,而不是“ h24:mi:ss”。

Can anyone help to convert this two data type affected from locale settings, with other two in UTC mode? 任何人都可以帮助转换受区域设置影响的这两种数据类型,而其他两种则处于UTC模式?

thanks for anyone just read this.. 感谢任何人,只要阅读此内容即可。

Javascript Date objects are based on a UTC time value . Javascript Date对象基于UTC时间值 When methods such as date.toString are called, the local system settings are used to show a local date and time. 当调用诸如date.toString类的方法时,本地系统设置用于显示本地日期和时间。

You can use Date.UTC to create a UTC time value, use that to create a date object, then use the date object to get a local (system) equivalent date and time. 您可以使用Date.UTC创建UTC时间值,使用该值创建日期对象,然后使用日期对象获取本地(系统)等效的日期和时间。

eg: 例如:

var utcDate = '20131012';
var utcTime = '223112';


// Get a UTC time value
var timeValue = Date.UTC(utcDate.substring(0,4),
                         utcDate.substring(4,6) - 1, // Months are zero indexed
                         utcDate.substring(6),
                         utcTime.substring(0,2),
                         utcTime.substring(2,4),
                         utcTime.substring(4)
                        ); 

// Convert time value to date object
var date = new Date(timeValue);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM