/doc/time.datetime.html
HTML | 92 lines | 86 code | 2 blank | 4 comment | 0 complexity | 030a38f1a64f1f70be81cb23ce7283c6 MD5 | raw file
1<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><!-- DW6 --> 2<head> 3<!-- #BeginEditable "doctitle" --> 4<title>PTypes: date/time: datetime</title> 5<!-- #EndEditable --> 6<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 7<link rel="stylesheet" href="styles.css"> 8</head> 9<body bgcolor="#FFFFFF" leftmargin="40" marginwidth="40"> 10<p><a href="../index.html"><img src="title-21.png" width="253" height="39" alt="C++ Portable Types Library (PTypes) Version 2.1" border="0"></a> 11<hr size="1" noshade> 12<!-- #BeginEditable "body" --> 13<p class="hpath"><a href="index.html">Top</a>: <a href="basic.html">Basic types</a>: 14<a href="time.html">Date/time</a>: Datetime type</p> 15<blockquote> 16<pre class="lang">#include <ptime.h> 17 18typedef large datetime; 19 20datetime now(bool utc = true); 21int days(datetime d); 22int msecs(datetime d); 23datetime mkdt(int days, int msecs); 24bool isvalid(datetime d); 25void tzupdate(); 26int tzoffset(); 27string dttostring(datetime d, const char* fmt); 28string nowstring(const char* fmt, bool utc = true); 29datetime utodatetime(time_t u);</pre> 30</blockquote> 31<p><span class="def">datetime now(bool utc = true)</span> returns the current 32date/time. The returned value can be either the local time or the Universal Coordinated 33Time (UTC, aka GMT), depending on the parameter <span class="lang">utc</span>. 34It is recommended to manipulate with the UTC time internally in your application 35whenever possible (f.ex. when it's not needed to display the time to the user), 36since in many countries the local time may be automatically adjusted when entering 37or leaving the daylight saving period, which may confuse your application. On 38the contrary, the UTC time never changes. That's why all modern operating systems 39rely on the UTC time internally. (See also <span class="lang">tzupdate()</span> 40below for additional notes).</p> 41<p><span class="def">int days(datetime d)</span> returns the number of days since 42the beginning of the calendar contained in the <span class="lang">datetime</span> 43value <span class="lang">d</span>.</p> 44<p><span class="def">int msecs(datetime d)</span> returns the number of milliseconds 45since midnight contained in the <span class="lang">datetime</span> value <span class="lang">d</span>.</p> 46<p><span class="def">datetime mkdt(int days, int msecs)</span> calculates the 47datetime value from <span class="lang">days</span> and <span class="lang">msecs</span> 48parameters. <span class="lang">Days</span> is the number of days since the beginning 49of the calendar, and <span class="lang">msecs</span> is the number of milliseconds 50since midnight. No checks are made for validity of these values. There exists 51an easier way to build a datetime value using <span class="lang">encodedate()</span> 52and <span class="lang">encodetime()</span> functions having the year, month and 53day numbers, as well as (not necessarily) the hour, minute, second and millisecond 54values.</p> 55<p><span class="def">bool isvalid(datetime d)</span> checks a <span class="lang">datetime</span> 56value for validity. The value of <span class="lang">d</span> is valid if it holds 57a time stamp between 01/01/0001 and 12/31/9999.</p> 58<p><span class="def">void tzupdate()</span> updates the internal timezone information, 59which affects the value of local time returned by <span class="lang">now()</span> 60and <span class="lang">nowstring()</span>. If your application is supposed to 61be running infinitely (e.g. if it's a network daemon), you might want to update 62the internal timezone information from time to time in order to return correct 63local time to the user on DST adjustment days. Depending on the precision of local 64time you wish to show to the user, you can call this function, for example, every 65minute or every hour. Without this, the local time may become incorrect at the 66moment of DST adjustment, which occurs twice a year in most countries.</p> 67<p><span class="def">int tzoffset()</span> returns the time zone offset in minutes. 68This value is negative in the West. Multiplying this value by 60000 (i.e. the 69offset in milliseconds) and adding it to the UTC <span class="lang">datetime</span> 70value will give the local time.</p> 71<p><span class="def">string dttostring(datetime d, const char* fmt)</span> converts 72a <span class="lang">datetime</span> value to string representation as specified 73by <span class="lang">fmt</span>. The syntax of the format specifier is the same 74as for <span class="lang">strftime()</span> (please, refer to the corresponding 75manual pages in your programming environment). Note that there might be slight 76incompatibilities between different implementations of <span class="lang">strftime()</span>. 77</p> 78<p><span class="def">string nowstring(const char* fmt, bool utc = true)</span> 79returns a string representing the current time in a format specified by <span class="lang">fmt</span>. 80<span class="lang">Utc</span> specifies whether the local time or the UTC time 81is required. Like for <span class="lang">dttostring()</span>, the syntax of the 82format specifier <span class="lang">fmt</span> is the same as for the system function 83<span class="lang">strftime()</span>.</p> 84<p><span class="def">datetime utodatetime(time_t u)</span> converts UNIX <span class="lang">time_t</span> 85value to PTypes <span class="lang">datetime</span>.</p> 86<p class="seealso">See also: <a href="time.calendar.html">Date/calendar manipulation</a>, 87<a href="time.time.html">Time manipulation</a></p> 88<!-- #EndEditable --> 89<hr size="1"> 90<a href="../index.html" class="ns">PTypes home</a> 91</body> 92<!-- #EndTemplate --></html>