Skip to content

Instantly share code, notes, and snippets.

@xenon92 xenon92/index.js
Created Jul 6, 2019

Embed
What would you like to do?
Simple Moment Validations (Nodejs)
"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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.