Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict"
- const moment = require('moment')
- class MomentValidations {
- constructor(dateTimeString) {
- this.dateTimeString = dateTimeString
- }
- isUtc() {
- let formatString = 'YYYY-MM-DDTHH:mm:ssZ'
- let dateObject = moment(this.dateTimeString, formatString, true)
- return dateObject.isValid()
- }
- }
- //Simple usage of a class in JS
- console.log(new MomentValidations("2019-05-11T12:05:37Z").isUtc()) //--> true
- //Directly using the library with the format specified
- console.log(moment("2019-05-11T12:05:37Z", 'YYYY-MM-DDTHH:mm:ssZ', true).isValid()) //--> true
- //Directly using the library using the internal ISO format in moment library
- console.log(moment("2019-05-11T12:05:37Z").isValid()) //--> true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement