Date Formats
As a software engineer you must know this.
What is Coordinated Universal Time?
Coordinated Universal Time or UTC time mean is commonly referred to as International Time.
- Universal Time (UT)
- Zulu Time (U.S. military)
- Greenwich Mean Time (GMT)
International Time was established by an international conference in 1884 as GMT.
There are 24 time zones on earth, ranging from -11 to +12. Each time zone is 15° in longitude, or one hour long. By definition, the prime meridian of Time Zone 0 is where Greenwich, England, is located. The local time in Greenwich, England, is UTC time. The UTC time hour plus or minus the local Time Zone will determine the local time in other areas. The local standard (real) time is extended by 1 hour during daylight savings time.
The 24-hour clock does not utilize “am” or “pm,” but rather runs from midnight to 11 p.m. (23 hours).
EST — Eastern Standard Time
CST — Central Standard Time
MST — Mountain Standard Time
PST — Pacific Standard Time
What is Daylight savings time (DTS)
Daylight saving time is applied throughout the summer in some areas.
Standard time is one hour earlier due to DST. When DST is implemented or when it returns to regular (real) time varies depending on the location. DST will ultimately be taken away since it was never feasible (obsolete).
SQL date time
The complexity of the situation is increased by SQL’s several data types that mix date and time representations. The DATETIME is the one that is used the most frequently because it has been around since prior versions of SQL. The format for DATETIME values returned by SQL is “YYYY-MM-DD hh:mm:ss.” From “1753–01–01 00:00:00” to “9999–12–31 23:59:59.997,” the supported range is.
GETDATE()
The current date and time may be obtained with this method. For instance,
SELECT GETDATE();
CURRENT_TIMESTAMP
The system’s current timestamp may be obtained using this function. For instance,
SELECT CURRENT_TIMESTAMP;
this function returns the current timestamp
Date/Time API
The following shortcomings of the previous date-time API are addressed with Java 8’s introduction of a new Date-Time API.
- Poor design — Default Date begins at 1900, month at 1, and day at 0, therefore there is no regularity. The previous API offered fewer straightforward date operation functions. The new API offers several useful ways for these kinds of activities.
- Not thread safe — java.util.Date is not thread safe, thus developers have to deal with concurrency issue while using date.The new date-time API lacks setter methods and is immutable.
- Difficult time zone handling − For timezone concerns, developers had to create a lot of code. Domain-specific design has been taken into consideration when creating the new API.
Joda Date /Time
Before Java 8, the date/time API had a number of architectural issues. The Date and SimpleDateFormatter classes’ lack of thread safety is one of the issues. Joda-Time employs immutable classes to handle date and time in order to solve this problem.
The Date class indicates a precise moment in time, down to the millisecond, rather than a real date. While most date operations typically utilize Epoch time, which begins on January 1st, 1970, the year in a Date starts from 1900. Additionally, a Date’s day, month, and year offsets make no sense. Days begin at 0 and months at 1, respectively. We must employ the Calendar class in order to access any of them. A clear and fluid API for managing dates and time is provided by Joda-Time. Java only supports two calendar systems, but Joda-Time supports eight.
Gregorian — java.util.GregorianCalendar
Japanese — java.util.JapaneseImperialCalendar.
Util Date /Time
The date and time in java are represented by a class called java.util. Date class provides method and constructors for handling time and date in Java, and Serializable, Comparable<Date> and Cloneable interfaces are implemented by java.util.Date class and java.sql. Date, java.sql.Time and java.sql. Timestamp interfaces are the base classes of the java.util.Date class.
The java.sql.Date extends java.util.Date class.
Date() — A Date object is initialized with the current date and time using this constructor. Milliseconds are measured to the nearest second.
Date(long millisecond) — In this constructor, a Date object is initialized to represent the number of milliseconds since January 1, 1970, 00:00:00 GMT. ( This time is the standard base time known as “the epoch”).
Class java.util.Date stores a date-time value as milliseconds since the epoch. java.sql.Date stores a date only value and is commonly used in JDBC.
Handling dates is tricky. We need to remember about special cases: leap seconds, different timezones etc. When dealing with JDBC we can use java.sql.Date with caution.
If we’re going to use java.util.Date, we need to remember about its shortcomings. If using Java 8 then better not to use java.util.Date at all.