@writetome51/get-date-time-id
v1.0.0
Published
Returns current date and time as string, with this default format: YYMMDD-HHMMSS-TZOffset . You have options to change format.
Downloads
2
Maintainers
Readme
getDateTimeID(options?): string
Returns current date and time as a string of digits.
// options:
{
includeFullYear?: boolean, // default false
ymdOrder?: 'ymd' | 'ydm' | 'myd' | 'mdy' | 'dym' | 'dmy', // default 'ymd'
hmsOrder?: 'hms' | 'hsm' | 'msh' | 'mhs' | 'smh' | 'shm', // default 'hms'
separator?: string, // default '-'
separateEach?: boolean, // default false
includeTimezoneOffset: boolean, // default true
}
getDefaultsFor_getDateTimeIDOptions(): Object
Returns default options for getDateTimeID()
.
Examples
getDateTimeID(); // Say date-time is May 22,2019, 2:22:10pm, in a time zone 2 hours ahead of GMT.
// --> '190522-142210+02'
getDateTimeID(); // Say date-time is May 22,2019, 2:22:10pm, in time zone 6 hours behind GMT.
// --> '190522-142210-06'
getDateTimeID({includeFullYear: true});
// --> '20190522-142210-06'
getDateTimeID({ymdOrder: 'mdy'});
// --> '052219-142210-06'
getDateTimeID({ymdOrder: 'mdy', separator: ''});
// --> '052219142210-06'
getDateTimeID({ymdOrder: 'mdy', separateEach: true});
// --> '05-22-19-14-22-10-06'
getDateTimeID({ymdOrder: 'mdy', hmsOrder: 'smh',
separateEach: true, includeTimezoneOffset: false}
);
// --> '05-22-19-10-22-14'
Installation
npm i @writetome51/get-date-time-id
Loading
// if using TypeScript:
import {getDateTimeID} from '@writetome51/get-date-time-id';
// if using ES5 JavaScript:
var getDateTimeID = require('@writetome51/get-date-time-id').getDateTimeID;