0

I am working on a project and i get dates from my IMAP client using imap_headerinfo(). I get 2021 24 02 01:44 when I want it to be 2021 24 02 13:44 aka. 24 hours format. How to I convert this?

code:

$header = imap_headerinfo($imap, $result[$i]);

$date = $header->date;
  • 5
    How are you gonna determine valid time without AM/PM ? – biesior Feb 24 '21 at 13:39
  • Im Norwegian, we usually use 24 hour format. – Daniel Høifødt Feb 24 '21 at 13:41
  • 1
    That's not what the question was about. It was about how you differ `01:44` you get from IMAP. How do you know when it's `13:44` and when it's actually `01:44` if it doesn't include AM/PM? – El_Vanja Feb 24 '21 at 13:42
  • 1
    I'm Polish, we also use 24h which is the best as we can see... however, how do you know that 01:44 is 01:44 or 13:44? without AM/PM part? converting is quite simple if you have this: https://stackoverflow.com/a/8742253/1066240 – biesior Feb 24 '21 at 13:44
  • Ok, I get it. But I would think te imap response has a clue what exact time it is... It does not show AM or PM... im thinking there is some settings to get the 24 hour format. – Daniel Høifødt Feb 24 '21 at 13:46
  • 1
    Use `udate` which has the Unix timestamp. Then you can convert it to whichever format your heart desires. – El_Vanja Feb 24 '21 at 13:53
  • Setting time format in 24h or Unix type, would be best option. Otherwise there's no way to guess. – biesior Feb 24 '21 at 13:55
  • Yes, please provide code or link to set the header to 24h format. =) Didn't find anything on it. – Daniel Høifødt Feb 24 '21 at 14:06
  • 1
    as mentioned by @el-vanja, you can use $header->udate instead of $header->date to retrieve message date in Unix time. – Anurat Chapanond Feb 24 '21 at 16:50
  • Ok, but udate shows only 1970 01 01 01:00 on webpage? Something more needed? – Daniel Høifødt Feb 26 '21 at 09:34

0 Answers0