V
V
Vitaly2015-10-05 17:12:16
JavaScript
Vitaly, 2015-10-05 17:12:16

how to format date in javascript?

I receive data from the database, there is a time graph in the format:
Fri Oct 02 2015 00:45:59 GMT+0300 (EEST)

But the client time is completely different.
You need to get the correct time (same as from the database) in the дд/мм/гггг чч:мм:сс.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2015-10-05
@Scorpiored88

var d = new Date('Fri Oct 02 2015 00:45:59 GMT+0300 (EEST)');

var formatDate = ('0' + d.getDate()).slice(-2) + '/' + ('0' + (d.getMonth() + 1)).slice(-2) + '/' + d.getFullYear() + ' ' + ('0' + d.getHours()).slice(-2) + ':' + ('0' + d.getMinutes()).slice(-2) + ':' + ('0' + d.getSeconds()).slice(-2);

console.log(formatDate); // 02/10/2015 00:45:59

PS I've been thinking, what's stopping you from formatting the date immediately upon request? In MySQL, this is the DATE_FORMAT() function
SELECT DATE_FORMAT(`my_date_column`, '%d/%m/%Y %H:%i:%s') AS `foramt_date` FROM `my_table`;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question