Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. "use strict"
  2.  
  3. const moment = require('moment')
  4.  
  5. class MomentValidations {
  6. constructor(dateTimeString) {
  7. this.dateTimeString = dateTimeString
  8. }
  9.  
  10. isUtc() {
  11. let formatString = 'YYYY-MM-DDTHH:mm:ssZ'
  12. let dateObject = moment(this.dateTimeString, formatString, true)
  13. return dateObject.isValid()
  14. }
  15. }
  16.  
  17. //Simple usage of a class in JS
  18. console.log(new MomentValidations("2019-05-11T12:05:37Z").isUtc()) //--> true
  19. //Directly using the library with the format specified
  20. console.log(moment("2019-05-11T12:05:37Z", 'YYYY-MM-DDTHH:mm:ssZ', true).isValid()) //--> true
  21. //Directly using the library using the internal ISO format in moment library
  22. console.log(moment("2019-05-11T12:05:37Z").isValid()) //--> true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement