Convert Unix timestamp to Readable Date/time

 

Hi guys,

I'm parsing some data from the net, but Date/Time on the page I'm parsing is in Unix timestamp format (example: 16557750000 is Tue, 21 Jun 2022 01:30:00 GMT).

How to convert it, any idea?

Thanks for your help, will be very much appreciated!

 
Relina:

Hi guys,

I'm parsing some data from the net, but Date/Time on the page I'm parsing is in Unix timestamp format (example: 16557750000 is Tue, 21 Jun 2022 01:30:00 GMT).

How to convert it, any idea?

Thanks for your help, will be very much appreciated!


Use the C++ code from this link https://www.geeksforgeeks.org/convert-unix-timestamp-to-dd-mm-yyyy-hhmmss-format/

It needs some cosmetic touch but I believe you will handle it :)

 
Relina: How to convert it, any idea?
  1. 16557750000 is 2049. You typed one extra zero.
  2. Same as a datetime; no conversion needed.
      datetime v=1655775000; Print(v); // 2022.06.21 01:30:00
    

 
Relina:

Hi guys,

I'm parsing some data from the net, but Date/Time on the page I'm parsing is in Unix timestamp format (example: 16557750000 is Tue, 21 Jun 2022 01:30:00 GMT).

How to convert it, any idea?

Thanks for your help, will be very much appreciated!

I see the time is in milliseconds

so you have to follow this

long gettime=16557750000; // get your time to parse for example 16557750000
long unixtime = gettime/1000;
datetime normaltime = (datetime)unixtime;
Print(normaltime);
 
Arpit T #: I see the time is in milliseconds

It is not.

 
William Roeder #:

It is not.

ye one zero  extra, the correct time is 1655775000 in ms

 
Arpit T #: ye one zero  extra, the correct time is 1655775000 in ms

Please pay attention. A Unix timestamp and MQL datetime are equivalent and both count number of seconds elapsed since January 01, 1970. They are both in seconds, and NOT in milliseconds.

 
Arpit T #: ye one zero  extra, the correct time is 1655775000 in ms

Not in ms.; in seconds.

 

Thanks guys for your replies!

And I did not type it wrong with one 0 extra! It is how it is (16557750000) on the page I'm parsing ...