0

I'm trying to change this date format :

$date= date('Y-m-d H:i:s')

in to this :

Jan 5, 2100 23:50:00

to use it here :

var acountDownDate = new Date("<?php echo $date?>").getTime();
Abdallah Sakre
  • 915
  • 1
  • 9
  • 26
  • This is possibly a duplicate. Check link https://stackoverflow.com/questions/10837022/convert-php-date-into-javascript-date-format – Fraddy Nov 10 '19 at 16:20
  • Possible duplicate of [Convert PHP date into javascript date format](https://stackoverflow.com/questions/10837022/convert-php-date-into-javascript-date-format) – Søren D. Ptæus Nov 10 '19 at 17:32

2 Answers2

1

Simply do format like this,

<?php
$end = date('F j, Y H:i:s');
echo $end;
?>

DEMO: https://3v4l.org/GSBZY

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
1

I'm trying to change this date format...in to this...Jan 5, 2100 23:50:00...to use it here...

Don't do that. That string is not in any format that JavaScript's Date object is supposed to parse.

Instead, use c which provides an ISO-8601 string, which the Date constructor supports.

$date= date('c')

Alternately, since what you want is the milliseconds Epoch value (number of milliseconds since midnight January 1st, 1970 GMT) (I can tell because you're using getTime() on the JavaScript Date), just output that directly rather than using Date. If the milliseconds part isn't really important, use time and multiply by 1000:

$date = time() * 1000

Then:

var acountDownDate = <?php echo $date?>;

If you want millisecond precision,

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875