Returns a JavaScript date object using the UTC timezone with optional offsets to adjust the
hour
,minute
,second
ormillisecond
.
import { utcTime } from 'nodemod/dist/utc-time/index.js';
(async () => {
/** NOTE: Assuming today's date is '2020-02-02' */
const defaultUTCDatetime = await utcTime();
const defaultUTCDatetimeWithOffsets = await utcTime({
offset: {
hour: 3,
minute: 2,
second: 1,
millisecond: 0,
},
});
const specifiedUTCDatetime = await utcTime({
startDatetime: '2033-03-03T03:33:33.333Z',
});
defaultUTCDatetime === new Date('2020-02-02T00:00:00.000Z'); /** true */
defaultUTCDatetimeWithOffsets === new Date('2020-02-02T03:02:01.000Z'); /** true */
specifiedUTCDatetime === new Date('2033-03-03T03:33:33.333Z'); /** true */
})();
offsets
<?Object> Optional offset values when returning a JavaScript Date object using UTC timezone.startDatetime
<?string|?number|?Date> Optional starting datetime. Defaults to today's datetime if it is not provided.
UTCTimeOpts
<?UTCTimeOpts> Optional configuration when returning a JavaScript Date object using UTC timezone.- returns: <Promise<string>> Promise which resolves with a JavaScript Date object using UTC timezone.
This methods works the same as utcTime([UTCTimeOpts])
except that this is the synchronous version.
MIT License © Rong Sen Ng