1

I get date_time from mssql db. Currently date come like that

 2021-01-30T15:08:25.393Z 

When I use this method;

    const date =date;
    var d = new Date(date).toUTCString()

My date is looking like

Sat, 30 Jan 2021 15:08:25 GMT
But, ı want to see date "dd/mm/yy hh:mm:ss"

How should I do this ?

rider
  • 69
  • 2
  • 12

1 Answers1

0

As I've checked in my Chrome tools JS you can mix up this methods:

const date = new Date('2021-01-30T15:08:25.393Z').toLocaleDateString('us')
const hours = new Date('2021-01-30T15:08:25.393Z').toLocaleTimeString('us')
console.log(`${date} ${hours}`)

and concat that results

Edited. I've found that

new Date('2021-01-30T15:08:25.393Z').toLocaleDateString('fr')

is way similar to what date format you need

Elisey
  • 137
  • 7
  • Thanks for your help, but when I write this, an hour comes 1 day and 3 hours ahead. – rider Jan 30 '21 at 18:37
  • `\`${new Date('2021-01-30T15:08:25.393Z').toLocaleDateString('fr')} ${new Date('2021-01-30T15:08:25.393Z').getUTCHours()}:${new Date('2021-01-30T15:08:25.393Z').getUTCMinutes()}:${new Date('2021-01-30T15:08:25.393Z').getUTCSeconds()} \`` Try to do something like that then. – Elisey Jan 30 '21 at 18:42
  • It was that way, you helped a lot, thank you – rider Jan 30 '21 at 18:47
  • The output of *toLocaleString* is implementation dependent, especially when no options are provided. That a particular language code/tag provides a certain format on one implementation does not mean the same format will be produced by other implementations. – RobG Jan 31 '21 at 01:37