Getting timestamp date in javascript

I have a time that looks like this: 2018/05/28 13:00 and I know that I should get it as a timestamp with the value of 1527512400000 (assuming GMT+0) but I didn’t find the correct method for that, any help?

12 thoughts on “Getting timestamp date in javascript”

  1. Assuming you get the date as

    var dateString = "2018/05/28 13:00"

    You can first create a Date object like this

    var date = new Date(dateString); // This will give you a date object based on your locale
    var dateGMTZero = new Date(`${dateString} +0000`); // this gives you a date Object with GMT +0000

    then for timestamp, you can parse the Date to an Integer

    var timestamp = +date; // + converts the object to an int

Leave a Comment