Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change date format using jQuery/Javascript?

Today I want to transfrom date into different format using jQuery/Javascript :

$date = '2013-04-01T19:45:11.000Z'
$cool = date('Y-m-d',strtotime($date));

How can I do that (PHP) in jQuery/Javascript ?

Thanks!

like image 296
Deptroco Avatar asked Dec 20 '22 00:12

Deptroco


1 Answers

Use the javascript date object.

<script>
  var date = new Date('2013-04-01T19:45:11.000Z');
  var day = date.getDate();
  var month = date.getMonth();
  var year = date.getFullYear();

  document.write(year + '-' + month + '-' + day);
</script>
like image 152
LeGrande Avatar answered Jan 05 '23 09:01

LeGrande