JavaScript: Creating timestamps with time zone offsets

Source: https://dzone.com/articles/javascript-creating-timestamps

Date.getTime() returns UTC

When you call getTime method on Date object you get the number of milliseconds from Unix epoch. Although your current Date object keeps time with some offset getTime gives seconds in UTC. Keep this in mind when creating timestamps if you are not living on zero-meridian.
var currentDate = selectedDate;          // current date with offset

var currentTime = currentDate.getTime(); // offset is ignored
This is pretty awkward, unexpected and unintuitive behavior but you have to keep in mind that all date and time calculations must use same time system to give appropriate results.

Không có nhận xét nào:

xóa toàn bộ commit

  Cách chuẩn & đơn giản nhất (Khuyến nghị) Mục tiêu Xóa toàn bộ commit history Giữ nguyên code hiện tại main chỉ còn 1 commit...