I have JSON code:
{ "time":"2015-10-20T11:20:00+02:00" }
I read that JSON from my script and the output in table is:
2015-10-20T11:20:00+02:00
However I want the output to be equal to that day and its time.
For example: Tue 20:00 (if my timezone is +02)
We can convert a string to datetime using strptime() function. This function is available in datetime and time modules to parse a string to datetime and time objects respectively.
Import the datetime library. Use the datetime. datetime class to handle date and time combinations. Use the strptime method to convert a string datetime to a object datetime.
You can format dates like this:
var date = new Date('2015-10-20T11:20:00+02:00');
var days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var output = days[date.getDay()] + ' ' + date.getHours() + ':' + date.getMinutes();
console.log(output);
// Tue 6:20
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With