Returns a JavaScript date object using the UTC timezone with optional offsets to adjust the
year
,month
, ordate
.
import { utcDate } from 'nodemod/dist/utc-date/index.js';
(async () => {
/** Assuming today's date is '2020-02-02' */
const defaultUTCDate = await utcDate();
const defaultUTCDateWithOffsets = await utcDate({
offset: {
year: 2,
month: 1,
day: 0,
},
});
const specifiedUTCDate = await utcDate({
startDate: '2030-03-02',
});
defaultUTCDate === new Date('2020-02-02T00:00:00.000Z'); /** true */
defaultUTCDateWithOffsets === new Date('2022-03-02T00:00:00.000Z'); /** true */
specifiedUTCDate === new Date('2030-03-02T00:00:00.000Z'); /** true */
})();
offsets
<?Object> Optional offset values when returning a JavaScript Date object using the UTC timezone.startDate
<?string|?number|?Date> Optional starting date. Defaults to today's date if it is not given.
UTCDateParams
<?UTCDateParams> Optional configuration when returning a JavaScript Date object using the UTC timezone.- returns: <Promise<Date>> Promise which resolves with a JavaScript Date object using the UTC timezone.
This methods works the same as utcDate([UTCDateParams])
except that this is the synchronous version.
MIT License © Rong Sen Ng