https://github.com/writetome51/get-ymd-hms
Functions receive Date and return object with keys 'ymd' (year month day) and 'hms' (hour minute second).
https://github.com/writetome51/get-ymd-hms
date-format date-formatting dates javascript times typescript utc ymd-hms
Last synced: about 2 months ago
JSON representation
Functions receive Date and return object with keys 'ymd' (year month day) and 'hms' (hour minute second).
- Host: GitHub
- URL: https://github.com/writetome51/get-ymd-hms
- Owner: writetome51
- License: mit
- Created: 2019-06-01T20:24:26.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-02-25T22:49:33.000Z (over 5 years ago)
- Last Synced: 2025-10-28T02:58:00.966Z (8 months ago)
- Topics: date-format, date-formatting, dates, javascript, times, typescript, utc, ymd-hms
- Language: TypeScript
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# get_ymd_hms_local(
date: Date,
options? = {includeFullYear: false}
): YMD_HMS
Returns `date` as `YMD_HMS` in local time.
# get_ymd_hms_UTC(
date: Date,
options? = {includeFullYear: false}
): YMD_HMS
Returns `date` as `YMD_HMS` in UTC (same as GMT) time.
These types are part of the public API:
# YMD_HMS = {ymd: Y_M_D, hms: H_M_S}
# Y_M_D = {y: string, m: string, d: string}
Each string has 2 digits, except: `y` will have 4 digits if `options.includeFullYear`
is `true`.
# H_M_S = {h: string, m: string, s: string}
Each string has 2 digits.
## Examples
```ts
let date = new Date();
get_ymd_hms_UTC(date, {includeFullYear: true});
// --> {ymd: {y: '2021', m: '02', d: '20'}, hms: {h: '20', m: '30', s: '30'}}
// (2021, February 20th, 8:30pm and 30 seconds, UTC)
get_ymd_hms_local(date, {includeFullYear: true});
// --> {ymd: {y: '2021', m: '02', d: '20'}, hms: {h: '13', m: '30', s: '30'}}
// (2021, February 20th, 1:30pm and 30 seconds, 7 hours behind UTC)
get_ymd_hms_local(date);
// --> {ymd: {y: '21', m: '02', d: '20'}, hms: {h: '13', m: '30', s: '30'}}
```
## Installation
`npm i @writetome51/get-ymd-hms`
## Loading
```ts
import { get_ymd_hms_local, get_ymd_hms_UTC } from '@writetome51/get-ymd-hms';
```
## License
[MIT](https://choosealicense.com/licenses/mit/)