By moonshine


2017-06-27 08:47:58 8 Comments

Am trying to learn angular2+ and i want to make a GoogleCalendar's like scheduler app. After many research, i decided to use PrimeNG. The output format of the calendar is

2016-01-16T16:00:00

that's seems great and complete. But the api i want to interract with uses timeStamp...

I tried to make a Javascript function who's parsing 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...

Did anyone know how can i interact corectly with the format i need to convert to a timestamp?

else did anyone know how can i get this date format ( 2016-01-16T16:00:00 ) to a timestamp using angular2+ ? Thanks very much !!

3 comments

@Berlin_Bro 2017-06-27 09:00:42

You are on the right path as far as i can see. I suggest you use the Javascript Date https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Date to create a new Date instead of trying to parse the raw output of primeng.

new Date() can be use with a multitude of parameters. If new Date(datestring) is not working out as I would expect, use split to split your output string into variables that u can use to fill

new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

This might be a little bit of sweat work but it should do the trick.

This is my first answer so please mods be gentle with my formatting.

@Dhyey 2017-06-27 09:02:15

You can use momentjs to get the desired timestamp.

eg: moment("2016-01-16T16:00:00").format("MM/DD/YYYY HH:mm:ss")

The output will be:

"01/16/2016 16:00:00"

@Igor Janković 2017-06-27 09:01:39

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.

Related Questions

Sponsored Content

39 Answered Questions

[SOLVED] Should I use the datetime or timestamp data type in MySQL?

20 Answered Questions

[SOLVED] How can one change the timestamp of an old commit in Git?

10 Answered Questions

[SOLVED] Java: Date from unix timestamp

  • 2010-07-30 12:22:45
  • RYN
  • 286190 View
  • 240 Score
  • 10 Answer
  • Tags:   java unix timestamp

19 Answered Questions

[SOLVED] How to convert date to timestamp in PHP?

  • 2008-09-22 08:41:20
  • Wizard4U
  • 885587 View
  • 353 Score
  • 19 Answer
  • Tags:   php date timestamp

39 Answered Questions

[SOLVED] How do you get a timestamp in JavaScript?

13 Answered Questions

[SOLVED] How to get the unix timestamp in C#

10 Answered Questions

[SOLVED] Create timestamp variable in bash script

3 Answered Questions

5 Answered Questions

[SOLVED] Ruby/Rails: converting a Date to a UNIX timestamp

2 Answered Questions

Sponsored Content