0

Possible Duplicate:
Convert a Unix timestamp to time in Javascript

I have been storing the user's date format preference in the database as a string of the format used by PHP's date() function.

A need has arisen for dates to be calculated by Javascript. Is anyone aware of some sort of mapping of the PHP format into Javascript?

From passing the PHP date format Ymd string to a Javascript function I would expect it to return 20010310

Community
  • 1
  • 1
MonOve
  • 1,091
  • 13
  • 34

2 Answers2

2

so you want this: http://phpjs.org/functions/date/

though i would strongly recommend you to use this: http://momentjs.com/

GottZ
  • 4,824
  • 1
  • 36
  • 46
  • In case you want to use the PHP formats: https://stackoverflow.com/questions/30186611/php-dateformat-to-moment-js-format – Mr. Jo Apr 13 '22 at 12:08
2

PHP:

$myDate = date('Ymd');

HTML:

<script type="text/javascript">
    var date = new Date(<?php echo strtotime($myDate); ?> * 1000);
</script>
Eugene Naydenov
  • 7,165
  • 2
  • 25
  • 43