問題描述
以 UTC 格式轉換日期時間 (Convert date time in utc)
i have to convert date in utc from locale date time in birt. 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'.
Can anyone help to convert this two data type affected from locale settings, with other two in UTC mode?
thanks for anyone just read this..
‑‑‑‑‑
參考解法
方法 1:
Javascript Date objects are based on a UTC time value. When methods such as date.toString
are called, the local system settings are used to show a local date and time.
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.
e.g.:
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);
(by AfanfeFana、RobG)