简体   繁体   中英

Convert 0x750201 to human readable date

So the date I have is 0x750201 which should include the year, month and day.

I've got the Javascript code that converts this to a date:

function getYMD(n) {
  // [y,m,d]
  return [(((n >> 16) & 0xFF) + 1900), ((n >>> 8) & 0xFF), (n & 0xFF)];
}

But I have no idea what it's doing and thus can't translate it to php, any ideas?

Here are some examples of what the code translate into:

0x750201 is 2017, 2, 1
0x75020e is 2017, 2, 14

Oh hah, thanks @Jaromanda X, didn't realise you could do this in PHP.

Turns out this does indeed work just fine, thanks for the help!

function getYMD($n) {
  // [y,m,d]
  return [((($n >> 16) & 0xFF) + 1900), (($n >> 8) & 0xFF), ($n & 0xFF)];
}
print_r(getYMD(0x750201));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM