js-func-date-to-unit

1.0.16 • Public • Published
npm install js-func-date-to-unit

DateToString

DateToString(new Date('2021-12-08T12:53:11.555+07:00'))

//2021-12-08T13:53:11.555+08:00

getUnitObjectFromDate

getUnitObjectFromDate('2021-12-08T00:00:00+07:00')

//{"Y":2021,"M":11,"D":8,"d":3,"h":1,"m":11,"s":0,"ms":0,"offset":{"offset":-480,"utc":{"pre":"+","h":"08","m":"00","fullString":"+08:00"}}}
//**Becareful: Month (M) are start from zero

timezoneOffsetToObject

timezoneOffsetToObject(new Date('2021-12-08T00:00:00+07:00').getTimezoneOffset())

//{"offset":-480,"utc":{"pre":"+","h":"08","m":"00","fullString":"+08:00"}}

UpdateDateStringWithUnit

UpdateDateStringWithUnit({
    date: '2021-12-08T00:00:00+07:00',
    units: {
        Y: 1995
    }
})

//1995-12-08T01:00:00+08:00

CreateDateStringWithUnit

With Target

update target date with unit and output string

CreateDateStringWithUnit({
    units: {
        D: 6,
        h: 11,
        m: 5,
        s: 5,
        offset: '+06:00'
    },
    targetDate: '2000-10-11T11:00:00+07:00'
})

//2000-10-06T11:05:05+06:00

No Target

update now date with unit and out string

CreateDateStringWithUnit({
    units: {
        D: 6,
        h: 11,
        m: 5,
        s: 5
    }
})

//2021-12-06T11:05:05+08:00

timezoneStringToOffset

+08:00 > -480

timezoneStringToOffset('+08:00');
//output: -480

syncDate

Convert local timezone to target timezone

with date

Thu Dec 09 2021 12:09:17 GMT+0300 (莫斯科標準時間) - UTC+03:00 convert to UTC+08:00 - > Thu Dec 09 2021 15:09:17 GMT+0300 (莫斯科標準時間)

syncDate({
    date: '2021-12-09T12:09:17'
    targetTimezone: '+08:00'
});

for now

syncDate({
    targetTimezone: '+08:00'
});

Package Sidebar

Install

npm i js-func-date-to-unit

Weekly Downloads

0

Version

1.0.16

License

MIT

Unpacked Size

6.74 kB

Total Files

3

Last publish

Collaborators

  • kye0038883