[ncl-talk] Date calculation of hours since "0001-01-01 00:00"

Jianyu Liu jerry_leo at msn.com
Mon Apr 9 02:46:18 MDT 2018


Hi,

Just noticed the inconsistent of date calculation of hours since "0001-01-01 00:00",   there are 2 days difference between NCL and other script/command, such as date, php.

Saying "17682542 hours since 0001-01-01 00:00",  NCL gave 2018-03-18 14:00,  Linux date command and php script gave 2018-03-20 14:00.   Wondering who is correct.

Here are the output of NCL
ncl 1> print (f->time)
Variable: time (file variable)
Type: double
Total Size: 8 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes:   [time | 1]
Coordinates:
            time: [17682542..17682542]
Number Of Attributes: 2
  units :       hours since 0001-01-01 00:00:00.0
  calendar :    standard
(0)     17682542

ncl 2> utc_date=cd_calendar(f->time,0)
ncl 3> print(utc_date)
Variable: utc_date
Type: float
Total Size: 24 bytes
            6 values
Number of Dimensions: 2
Dimensions and sizes:   [1] x [6]
Coordinates:
Number Of Attributes: 1
  calendar :    standard
(0,0)   2018
(0,1)    3
(0,2)   18
(0,3)   14
(0,4)    0
(0,5)   1.341105e-05
Here are the output of date command

    date -d "17682542 hours 0001-01-01 00:00" +"%Y-%m-%d %H:%M"

2018-03-20 14:00

Here are the output of PHP

    ini_set('date.timezone', 'UTC');
    $t=strtotime('0001-01-01  +17682542 hours) ;
    echo date('Y-m-d H:i', $t);

2018-03-20 14:00

Thanks for your time

Regards

Jerry


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180409/f3a31c32/attachment.html>


More information about the ncl-talk mailing list