⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datetime.sgml

📁 PostgreSQL7.4.6 for Linux
💻 SGML
📖 第 1 页 / 共 2 页
字号:
<!--$Header: /cvsroot/pgsql/doc/src/sgml/datetime.sgml,v 2.36.2.2 2003/12/01 20:35:04 tgl Exp $--> <appendix id="datetime-appendix">  <title>Date/Time Support</title>  <para>   <productname>PostgreSQL</productname> uses an internal heuristic   parser for all date/time input support. Dates and times are input as   strings, and are broken up into distinct fields with a preliminary   determination of what kind of information may be in the   field. Each field is interpreted and either assigned a numeric   value, ignored, or rejected.   The parser contains internal lookup tables for all textual fields,   including months, days of the week, and time   zones.  </para>  <para>   This appendix includes information on the content of these   lookup tables and describes the steps used by the parser to decode   dates and times.  </para>  <sect1>   <title>Date/Time Input Interpretation</title>   <para>    The date/time type inputs are all decoded using the following procedure.   </para>   <procedure>    <step>     <para>      Break the input string into tokens and categorize each token as      a string, time, time zone, or number.     </para>     <substeps>      <step>       <para>	If the numeric token contains a colon (<literal>:</>), this is	a time string. Include all subsequent digits and colons.       </para>      </step>      <step>       <para>	If the numeric token contains a dash (<literal>-</>), slash	(<literal>/</>), or two or more dots (<literal>.</>), this is	a date string which may have a text month.       </para>      </step>      <step>       <para>	If the token is numeric only, then it is either a single field	or an ISO 8601 concatenated date (e.g.,	<literal>19990113</literal> for January 13, 1999) or time	(e.g., <literal>141516</literal> for 14:15:16).       </para>      </step>      <step>       <para>	If the token starts with a plus (<literal>+</>) or minus	(<literal>-</>), then it is either a time zone or a special	field.       </para>      </step>     </substeps>    </step>    <step>     <para>      If the token is a text string, match up with possible strings.     </para>          <substeps>      <step>       <para>	Do a binary-search table lookup for the token	as either a special string (e.g., <literal>today</literal>),	day (e.g., <literal>Thursday</literal>),	month (e.g., <literal>January</literal>),	or noise word (e.g., <literal>at</literal>, <literal>on</literal>).       </para>       <para>	Set field values and bit mask for fields.	For example, set year, month, day for <literal>today</literal>,	and additionally hour, minute, second for <literal>now</literal>.       </para>      </step>            <step>       <para>	If not found, do a similar binary-search table lookup to match	the token with a time zone.       </para>      </step>      <step>       <para>	If still not found, throw an error.       </para>      </step>     </substeps>    </step>        <step>     <para>      When the token is a number or number field:     </para>     <substeps>      <step>       <para>	If there are eight or six digits,	and if no other date fields have been previously read, then interpret 	as a <quote>concatenated date</quote> (e.g.,	<literal>19990118</literal> or <literal>990118</literal>).	The interpretation is <literal>YYYYMMDD</> or <literal>YYMMDD</>.       </para>      </step>      <step>       <para>	If the token is three digits	and a year has already been read, then interpret as day of year.       </para>      </step>            <step>       <para>	If four or six digits and a year has already been read, then	interpret as a time (<literal>HHMM</> or <literal>HHMMSS</>).       </para>      </step>      <step>       <para>	If three or more digits and no date fields have yet been found,	interpret as a year (this forces yy-mm-dd ordering of the remaining	date fields).       </para>      </step>      <step>       <para>        Otherwise the date field ordering is assumed to follow the	<varname>DateStyle</> setting: mm-dd-yy, dd-mm-yy, or yy-mm-dd.	Throw an error if a month or day field is found to be out of range.       </para>      </step>     </substeps>    </step>    <step>     <para>      If BC has been specified, negate the year and add one for      internal storage.  (There is no year zero in the Gregorian      calendar, so numerically 1 BC becomes year      zero.)     </para>    </step>    <step>     <para>      If BC was not specified, and if the year field was two digits in length, then      adjust the year to four digits. If the field is less than 70, then add 2000,      otherwise add 1900.      <tip>       <para>	Gregorian years AD 1-99 may be entered by using 4 digits with leading	zeros (e.g., <literal>0099</> is AD 99). Previous versions of	<productname>PostgreSQL</productname> accepted years with three	digits and with single digits, but as of version 7.0 the rules have	been tightened up to reduce the possibility of ambiguity.       </para>      </tip>     </para>    </step>   </procedure>  </sect1>  <sect1 id="datetime-keywords">   <title>Date/Time Key Words</title>   <para>    <xref linkend="datetime-month-table"> shows the tokens that are    permissible as abbreviations for the names of the month.   </para>    <table id="datetime-month-table">     <title>Month Abbreviations</title>     <tgroup cols="2">      <thead>       <row>	<entry>Month</entry>	<entry>Abbreviations</entry>       </row>      </thead>      <tbody>       <row>	<entry>April</entry>	<entry>Apr</entry>       </row>       <row>	<entry>August</entry>	<entry>Aug</entry>       </row>       <row>	<entry>December</entry>	<entry>Dec</entry>       </row>       <row>	<entry>February</entry>	<entry>Feb</entry>       </row>       <row>	<entry>January</entry>	<entry>Jan</entry>       </row>       <row>	<entry>July</entry>	<entry>Jul</entry>       </row>       <row>	<entry>June</entry>	<entry>Jun</entry>       </row>       <row>	<entry>March</entry>	<entry>Mar</entry>       </row>       <row>	<entry>November</entry>	<entry>Nov</entry>       </row>       <row>	<entry>October</entry>	<entry>Oct</entry>       </row>       <row>	<entry>September</entry>	<entry>Sep, Sept</entry>       </row>      </tbody>     </tgroup>    </table>    <note>     <para>      The month May has no explicit abbreviation, for obvious reasons.     </para>    </note>    <para>     <xref linkend="datetime-dow-table"> shows the tokens that are     permissible as abbreviations for the names of the days of the     week.    </para>     <table id="datetime-dow-table">      <title>Day of the Week Abbreviations</title>      <tgroup cols="2">       <thead>	<row>	 <entry>Day</entry>	 <entry>Abbreviation</entry>	</row>       </thead>       <tbody>	<row>	 <entry>Sunday</entry>	 <entry>Sun</entry>	</row>	<row>	 <entry>Monday</entry>	 <entry>Mon</entry>	</row>	<row>	 <entry>Tuesday</entry>	 <entry>Tue, Tues</entry>	</row>	<row>	 <entry>Wednesday</entry>	 <entry>Wed, Weds</entry>	</row>	<row>	 <entry>Thursday</entry>	 <entry>Thu, Thur, Thurs</entry>	</row>	<row>	 <entry>Friday</entry>	 <entry>Fri</entry>	</row>	<row>	 <entry>Saturday</entry>	 <entry>Sat</entry>	</row>       </tbody>      </tgroup>     </table>   <para>    <xref linkend="datetime-mod-table"> shows the tokens that serve    various modifier purposes.   </para>    <table id="datetime-mod-table">     <title>Date/Time Field Modifiers</title>     <tgroup cols="2">      <thead>       <row>	<entry>Identifier</entry>	<entry>Description</entry>       </row>      </thead>      <tbody>       <row>	<entry><literal>ABSTIME</literal></entry>	<entry>Key word ignored</entry>       </row>       <row>	<entry><literal>AM</literal></entry>	<entry>Time is before 12:00</entry>       </row>       <row>	<entry><literal>AT</literal></entry>	<entry>Key word ignored</entry>       </row>       <row>	<entry><literal>JULIAN</>, <literal>JD</>, <literal>J</></entry>	<entry>Next field is Julian Day</entry>       </row>       <row>	<entry><literal>ON</literal></entry>	<entry>Key word ignored</entry>       </row>       <row>	<entry><literal>PM</literal></entry>	<entry>Time is on or after 12:00</entry>       </row>       <row>	<entry><literal>T</literal></entry>	<entry>Next field is time</entry>       </row>      </tbody>     </tgroup>    </table>   <para>    The key word <literal>ABSTIME</literal> is ignored for historical    reasons: In very old releases of    <productname>PostgreSQL</productname>, invalid values of type <type>abstime</type>    were emitted as <literal>Invalid Abstime</literal>. This is no    longer the case however and this key word will likely be dropped in    a future release.   </para>   <indexterm>    <primary>time zone</primary>    <secondary>abbreviations</secondary>   </indexterm>   <para>    <xref linkend="datetime-timezone-table"> shows the time zone    abbreviations recognized by <productname>PostgreSQL</productname>    in date/time input values.    <productname>PostgreSQL</productname> uses internal tables    for time zone input decoding, since there is no standard    operating system interface to provide access to general,    cross-time zone information. The underlying operating system    <emphasis>is</emphasis> used to provide time zone information for    <emphasis>output</emphasis>, however.   </para>   <para>    Keep in mind also that the time zone names    recognized by <command>SET TIMEZONE</> are operating-system    dependent and may have little to do with <xref    linkend="datetime-timezone-table">.  For example, some systems    recognize values like <literal>'Europe/Rome'</> in <command>SET    TIMEZONE</>.   </para>   <para>    The table is organized by time zone offset from <acronym>UTC</>,    rather than alphabetically.  This is intended to facilitate    matching local usage with recognized abbreviations for cases where    these might differ.   </para>    <table id="datetime-timezone-table">     <title>Time Zone Abbreviations</title>     <tgroup cols="3">      <thead>       <row>	<entry>Time Zone</entry>	<entry>Offset from UTC</entry>	<entry>Description</entry>       </row>      </thead>      <tbody>       <row>	<entry>NZDT</entry>	<entry>+13:00</entry>	<entry>New Zealand Daylight-Saving Time</entry>       </row>       <row>	<entry>IDLE</entry>	<entry>+12:00</entry>	<entry>International Date Line, East</entry>       </row>       <row>	<entry>NZST</entry>	<entry>+12:00</entry>	<entry>New Zealand Standard Time</entry>       </row>       <row>	<entry>NZT</entry>	<entry>+12:00</entry>	<entry>New Zealand Time</entry>       </row>       <row>	<entry>AESST</entry>	<entry>+11:00</entry>	<entry>Australia Eastern Summer Standard Time</entry>       </row>       <row>	<entry>ACSST</entry>	<entry>+10:30</entry>	<entry>Central Australia Summer Standard Time</entry>       </row>       <row>	<entry>CADT</entry>	<entry>+10:30</entry>	<entry>Central Australia Daylight-Saving Time</entry>       </row>       <row>	<entry>SADT</entry>	<entry>+10:30</entry>	<entry>South Australian Daylight-Saving Time</entry>       </row>       <row>	<entry>AEST</entry>	<entry>+10:00</entry>	<entry>Australia Eastern Standard Time</entry>       </row>       <row>	<entry>EAST</entry>	<entry>+10:00</entry>	<entry>East Australian Standard Time</entry>       </row>       <row>	<entry>GST</entry>	<entry>+10:00</entry>	<entry>Guam Standard Time, Russia zone 9</entry>       </row>       <row>	<entry>LIGT</entry>	<entry>+10:00</entry>	<entry>Melbourne, Australia</entry>       </row>       <row>	<entry>SAST</entry>	<entry>+09:30</entry>	<entry>South Australia Standard Time</entry>       </row>       <row>	<entry>CAST</entry>	<entry>+09:30</entry>	<entry>Central Australia Standard Time</entry>       </row>       <row>	<entry>AWSST</entry>	<entry>+09:00</entry>	<entry>Australia Western Summer Standard Time</entry>       </row>       <row>	<entry>JST</entry>	<entry>+09:00</entry>	<entry>Japan Standard Time, Russia zone 8</entry>       </row>       <row>	<entry>KST</entry>	<entry>+09:00</entry>	<entry>Korea Standard Time</entry>       </row>       <row>	<entry>MHT</entry>	<entry>+09:00</entry>	<entry>Kwajalein Time</entry>       </row>       <row>	<entry>WDT</entry>	<entry>+09:00</entry>	<entry>West Australian Daylight-Saving Time</entry>       </row>       <row>	<entry>MT</entry>	<entry>+08:30</entry>	<entry>Moluccas Time</entry>       </row>       <row>	<entry>AWST</entry>	<entry>+08:00</entry>	<entry>Australia Western Standard Time</entry>       </row>       <row>	<entry>CCT</entry>	<entry>+08:00</entry>	<entry>China Coastal Time</entry>       </row>       <row>	<entry>WADT</entry>	<entry>+08:00</entry>	<entry>West Australian Daylight-Saving Time</entry>       </row>       <row>	<entry>WST</entry>	<entry>+08:00</entry>	<entry>West Australian Standard Time</entry>       </row>       <row>	<entry>JT</entry>	<entry>+07:30</entry>	<entry>Java Time</entry>       </row>       <row>	<entry>ALMST</entry>	<entry>+07:00</entry>	<entry>Almaty Summer Time</entry>       </row>       <row>	<entry>WAST</entry>	<entry>+07:00</entry>	<entry>West Australian Standard Time</entry>       </row>       <row>	<entry>CXT</entry>	<entry>+07:00</entry>	<entry>Christmas (Island) Time</entry>       </row>       <row>	<entry>MMT</entry>	<entry>+06:30</entry>	<entry>Myanmar Time</entry>       </row>       <row>	<entry>ALMT</entry>	<entry>+06:00</entry>	<entry>Almaty Time</entry>       </row>       <row>	<entry>MAWT</entry>	<entry>+06:00</entry>	<entry>Mawson (Antarctica) Time</entry>       </row>       <row>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -