<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Dear Jerry,</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I checked your date conversion in Matlab as well by the following way:</p>
<p style="margin-top:0;margin-bottom:0">I divided <span>17682542</span> 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 (<span>736772.6</span> +
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).</p>
<p style="margin-top:0;margin-bottom:0">Furthermore, I checked the date -d <span>
"<span><span><span>17682542 hours 0001-01-01 00:00"</span></span></span> +"%Y-%m-%d %H:%M"</span> function on different linux system and I got different date values:</p>
<p style="margin-top:0;margin-bottom:0">Debian (GNU/Lin 8): 2018-03-20 13:43</p>
<p style="margin-top:0;margin-bottom:0">Ubuntu 14.04: 2018-03-20 14:02</p>
<p style="margin-top:0;margin-bottom:0">Linux 3.10.0: 2018-03-20 14:00.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">I hope I could help you!</p>
<p style="margin-top:0;margin-bottom:0">Best regards,</p>
<p style="margin-top:0;margin-bottom:0">Beata<br>
</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> ncl-talk <ncl-talk-bounces@ucar.edu> on behalf of Jianyu Liu <jerry_leo@msn.com><br>
<b>Sent:</b> Monday, April 9, 2018 10:46:18 AM<br>
<b>To:</b> ncl-talk@ucar.edu<br>
<b>Subject:</b> [ncl-talk] Date calculation of hours since "0001-01-01 00:00"</font>
<div> </div>
</div>
<style type="text/css" style="display:none">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0; margin-bottom:0"></p>
<div>Hi, <br>
<br>
Just noticed the inconsistent of <span>date calculation of hours since "0001-01-01 00:00"</span><span>,
<span>there are 2 days difference between NCL and other script/command, such as date, php.
</span><br>
<br>
Saying <span><span>"17682542 hours since 0001-01-01 00:00"</span></span>, NCL gave
<span><span><span>2018</span>-03-18 14:00</span></span>, Linux date command and php script gave
<span><span><span><span>2018</span>-03-20 14:00</span></span></span>. </span><span> Wondering who is correct.
<br>
<br>
Here are the output of NCL<br>
</span>
<blockquote><span>
<div>ncl 1> print (f->time) </div>
</span></blockquote>
<blockquote><span>
<div>Variable: time (file variable)</div>
</span><span>
<div>Type: double</div>
</span><span>
<div>Total Size: 8 bytes</div>
</span><span>
<div> 1 values</div>
</span><span>
<div>Number of Dimensions: 1</div>
</span><span>
<div>Dimensions and sizes: [time | 1]</div>
</span><span>
<div>Coordinates:</div>
</span><span>
<div> time: [17682542..17682542]</div>
</span><span>
<div>Number Of Attributes: 2</div>
</span><span>
<div> units : hours since 0001-01-01 00:00:00.0</div>
</span><span>
<div> calendar : standard</div>
</span><span>
<div>(0) 17682542</div>
</span><br>
<span>
<div>ncl 2> utc_date=cd_calendar(f->time,0)</div>
</span><span>
<div>ncl 3> print(utc_date)</div>
</span><span>
<div>Variable: utc_date</div>
</span><span>
<div>Type: float</div>
</span><span>
<div>Total Size: 24 bytes</div>
</span><span>
<div> 6 values</div>
</span><span>
<div>Number of Dimensions: 2</div>
</span><span>
<div>Dimensions and sizes: [1] x [6]</div>
</span><span>
<div>Coordinates:</div>
</span><span>
<div>Number Of Attributes: 1</div>
</span><span>
<div> calendar : standard</div>
</span><span>
<div>(0,0) 2018</div>
</span><span>
<div>(0,1) 3</div>
</span><span>
<div>(0,2) 18</div>
</span><span>
<div>(0,3) 14</div>
</span><span>
<div>(0,4) 0</div>
</span><span>
<div>(0,5) 1.341105e-05</div>
</span></blockquote>
<span><span>Here are the output of date command</span><br>
<br>
date -d "<span><span><span>17682542 hours 0001-01-01 00:00"</span></span></span> +"%Y-%m-%d %H:%M"<br>
<br>
<span><span>2018</span>-03-20 14:00</span><br>
<br>
<span><span>Here are the output of</span></span> PHP<br>
<br>
ini_set('date.timezone', 'UTC');<br>
$t=strtotime('0001-01-01 +<span><span><span>17682542 hours</span></span></span>) ;<br>
<span></span></span><span></span> echo date('Y-m-d H:i', $t);<br>
<br>
2018-03-20 14:00<br>
<br>
Thanks for your time <br>
<br>
Regards<br>
<br>
Jerry<br>
<br>
<br>
</div>
<p></p>
</div>
</div>
</body>
</html>