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

Beáta Szabó-Takács szabo.b at czechglobe.cz
Mon Apr 16 08:22:39 MDT 2018


Dear Jerry,


I checked your date conversion in Matlab as well by the following way:

I divided 17682542 hours by 24 to get days (736772.6 days). I calculated the serial date number of 0001.01.01 00:00:00 by datenum function which is 372 days. I added up these days (736772.6 + 372) and used this value in datevec function which resulted 2018.03.20 14:00. In my view, the NCL cd_calendar function is correct because in Gregorian calendar there are no double leap years (372 days).

Furthermore, I checked the date -d "17682542 hours 0001-01-01 00:00" +"%Y-%m-%d %H:%M" function on different linux system and I got different date values:

Debian (GNU/Lin 8): 2018-03-20 13:43

Ubuntu 14.04: 2018-03-20 14:02

Linux 3.10.0: 2018-03-20 14:00.


I hope I could help you!

Best regards,

Beata

________________________________
From: ncl-talk <ncl-talk-bounces at ucar.edu> on behalf of Jianyu Liu <jerry_leo at msn.com>
Sent: Monday, April 9, 2018 10:46:18 AM
To: ncl-talk at ucar.edu
Subject: [ncl-talk] Date calculation of hours since "0001-01-01 00:00"


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/20180416/2b8ed62e/attachment.html>


More information about the ncl-talk mailing list