Is there an alternative data type "Date" that is more "ambiguous" than UTC?
A typical datatype Date
, in most programming languages, is a Unix timestamp, which is a "precise point in time".
But I want to know if there is a more "ambiguous" structure Date
that more accurately reflects the human perception of dates.
For example, say I want to represent a specific year ( 2000
) or a specific month ( January 2000
) or a specific day ( January 1, 2000
)?
I could save it as a Unix timestamp that would be 1/1/2000 12:00 AM GMT
.
But computers interpret timestamps according to their local time zone, so my computer will show 12/31/1999 5:00 PM PDT
and each computer will interpret it differently.
Since Unix timestamps seem to be the standard for precise points in time, I'm just wondering if there is any standard for ambiguous points in time.
If there is no standard, I would be happy to read about any specific implementations ( in any language ) that handle these scripts.
source to share
Yes, there are many places you will come across:
-
In the ISO-8601 standard as a string in the YYYY-MM-DD format. For example,
"2014-10-08"
October 8th, 2014. -
In .NET languages such as C #, type
DateTime
is date and time, but it is not necessarily associated with a specific point in time. This depends on the internal propertiesKind
which can be eitherUtc
,Local
orUnspecified
. When not specified, it is simply a date and time with no reference to any time zone. It still has a time component. -
In the .NET library, Noda Time
LocalDate
is a pure date with no time or time zone. Likewise,LocalDateTime
is a date and time type without a time zone. -
In the Java library, Joda Time
LocalDate
is a pure date with no time or time zone. Likewise,LocalDateTime
is a date and time type without a time zone. You will also find these types in the newjava.time
API in Java 8 . -
In C or C ++, the structure
tm
represents the date and time of the calendar, regardless of the time zone. It is in the standard library along with a frameworkt_time
which has the behavior you described in your question. -
In Python, an object
date
represents a date without a time or time zone. The objectDateTime
represents a date and time with an optional time zone. Python calls them naive when there is no time zone information and knows when a time zone is provided. -
Many databases have date and time or date-only data types regardless of the time zone. I will not list all databases, but I will consider Microsoft SQL Server, which has a separate
DateTime
anddate
.
I am sure there are many others, however they do not necessarily exist for all languages. For example, PHP has a class DateTime
, but it knows about the timezone, and I don't believe there is a class that is not (or I couldn't find it anyway). JavaScript is another example as its object date
is a datetime object bound to a UTC-based timestamp.
source to share