Reputation: 206
I was wondering how I would go about converting the SQL timestamp format (2016-04-30T01:19:45.000Z) to a standard date format like (30/04/2016) using Javascript/front-end-technology.
Thanks in advance.
Upvotes: 4
Views: 4992
Reputation: 487
It depends on how many operations you want to do. If it is more than one, then i would recommend using a library like momentJS. It makes timestamp conversion very simple. See example below.
MySQL date string:
var sqlDate = new Date('2016-04-30T01:19:45.000z');
var now = moment(sqlDate).format('l');
console.log( now );
Upvotes: 4
Reputation: 1335
Hope this helps. This can be achieved in multiple ways - pure JavaScript, jQuery, Angular etc., As well it requires bit of tweaking based on your requirement. Do let me know if this helps
<script>
var myDate = new Date('2010-10-11T00:00:00+05:30');
alert((myDate.getMonth() + 1) + '/' + myDate.getDate() + '/' + myDate.getFullYear());
</script>
Upvotes: 9