Calculating dates in Luxon with the plus,minus method

Calculating dates in Luxon with the plus,minus method

item version
Luxon 2.4.0

I’m going to use Luxon in node.js library for dates.

It calculates dates, using the plus method.

import {DateTime, Duration} from 'luxon'
let now
now = DateTime.fromFormat('2022-06-23T13:22:40.341+09:00', 'yyyy-MM-dd\'T\'TT.SSSZZ')
let ret
ret ={days: 1})
console.log(ret.toString()) // 2022-06-24T13:22:40.341+09:00
ret ={days: -1})
console.log(ret.toString()) // 2022-06-22T13:22:40.341+09:00
ret ={minutes: 1})
console.log(ret.toString()) // 2022-06-23T13:23:40.341+09:00
ret ={minutes: -1})
console.log(ret.toString()) // 2022-06-23T13:21:40.341+09:00
ret ={hours: 1})
console.log(ret.toString()) // 2022-06-23T14:22:40.341+09:00
ret ={hours: -1})
console.log(ret.toString()) // 2022-06-23T12:22:40.341+09:00
ret ={ hours: 3, minutes: 13 })
console.log(ret.toString()) // 2022-06-23T16:35:40.341+09:00
ret ={ hours: 3, minutes: 13 })) // Add 03:15.
console.log(ret.toString()) // 2022-06-23T16:35:40.341+09:00

The minus method has the same arguments as the plus method.


Discover more from 株式会社CONFRAGE ITソリューション事業部

Subscribe now to keep reading and get access to the full archive.

Continue reading

Copied title and URL