Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert string into real time date&time

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)

like image 760
Kunok Avatar asked Nov 22 '15 04:11

Kunok


People also ask

How do you convert string to time?

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.

How do I convert a string to a timestamp in python?

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.


1 Answers

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
like image 199
David Zorychta Avatar answered Oct 18 '22 05:10

David Zorychta