Search code examples
angulartimestampprimeng

date + time to timestamp in angular2


I want to make a Google Calendar-like scheduler app.

I decided to use PrimeNG. The output format of the calendar is

2016-01-16T16:00:00

The API I want to interact with uses timeStamp.

I tried to make a JavaScript function to prase my date format:

function toTimestamp(strDate){
   var datum = Date.parse(strDate);
   return datum/1000;
}
alert(toTimestamp('02/13/2009 23:31:30'));

But my problem is that I can't use the format of PrimeNG.

How can I interact correctly with the format I need to convert to a timestamp?

Otherwise, how I can get this date format (2016-01-16T16:00:00) to a timestamp using Angular 2?


Solution

  • You can use plain javascript:

    let time = new Date("2016-01-16T16:00:00");
    alert(time.getTime());
    

    This will return you a timestamp. Just be aware of timezones.