25 April 2005
Representing time in C, C++, SQL, MFC, and Java
Options available in representing date and time values:
18 Jan 2006: Added java.util.Date
5 Apr 2006: Added Data column for types
(Links are to MSDN unless otherwise noted.)
Data Representations
Type | Domain | Header | Data |
tm | C (struct) | time.h |
|
time_t, __time64_t | C (long) | time.h | |
SYSTEMTIME | Win32 (C struct) | winbase.h |
|
FILETIME | Win32 (C struct) | winbase.h |
|
DATE | COM (double) | wtypes.h | |
DBTIMESTAMP | COM (C struct) | oledb.h |
|
CTime | MFC (class, stored as time_t member) | afx.h | |
COleDateTime | MFC (class, stored as DATE member) | afxdisp.h | |
java.util.Date | Java |
Conversion
From Types -> To Types V |
tm | time_t, __time64_t | SYSTEM TIME | FILE TIME | DATE | DBTIME STAMP | CTime | COle DateTime | java.util. Date |
tm | gmtime, localtime, _gmtime64, _localtime64 | X | |||||||
time_t, __time64_t | mktime, _mktime64 | time, _time64 (current system time) | X | Date. getTime() / 1000 | |||||
SYSTEM TIME | FileTime ToSystemTime | ||||||||
FILETIME | SystemTime ToFileTime | ||||||||
DATE | |||||||||
DBTIME STAMP | |||||||||
CTime | X | X | X | X | |||||
COle DateTime | X | X | X | X | X | ||||
java.util. Date | new Date(time_t * 1000) |
Limits
SQL information taken from How to search for date and time values using Microsoft SQL Server 2000 by Bryan Syverson and MySQL Reference Manual :: 11.3.1 The DATETIME, DATE, and TIMESTAMP Types.
Type | Minimum (YYYY-MM-DD) | Maximum (YYYY-MM-DD) | Precision |
SQL datetime | 1753-01-01 (SQL Server), 1000-01-01 (MySQL) | 9999-12-31 | To the nearest 3.33 milliseconds |
SQL smalldatetime | 1900-01-01 | 2079-06-06 23:59 (1 minute until midnight) | To the nearest minute |
time_t/tm, __time64_t | 1970-01-01 00:00:00 | 2038-01-18 19:14:07, 3000-12-31 23:59:59 | seconds from the minimum time |
FILETIME | 1601-01-01 | ||
DATE | Zero is 1899-12-31 00:00:00 | ||
CTime | 1970-01-01 | 2038-01-18 | |
COleDateTime | 0100-01-01 | 9999-12-31 | |
java.util.Date | zero is 1970-01-01 00:00:00, milliseconds from zero |
TODO: Add relevant functions, facets, and boost utilities.
[ posted by sstrader on
25 April 2005 at 10:41:17 AM in Programming
]
- Techniques after using Swift for a month posted by sstrader on 26 August 2015 at 11:41:51 PM
- Some thoughts on Ruby after finishing a week (minus one day) of training posted by sstrader on 15 December 2011 at 8:59:30 PM
- Links on the singleton pattern posted by sstrader on 9 December 2011 at 9:19:50 AM
- Phonebot posted by sstrader on 29 October 2011 at 6:37:05 PM
- The labeled break in Java posted by sstrader on 4 September 2011 at 11:27:56 AM
Related entries
Other entries categorized in Programming: