Sitemap
Nafees

Nafees

Undergraduate Student of University of Jaffna || Associate Software Engineer

Date Formats

4 min readOct 31, 2022

--

Hello Everyone,

Today We can learn about Date Formats.

What is Coordinated Universal Time?

Coordinated universal time which is abbreviated as UTC is significant because it is the standard time of the world. It is also known as Universal time (UT), Zulu time, and Greenwich mean time (GMT). This is commonly referred to as international time.

International Time was established by an international conference in 1884 as GMT.

Earth is divided into 24 time zones from -11 to +12 and each time zone is 1 hour long or 15° longitude. By definition, Greenwich, England is on the prime meridian of time zone 0. Local time in other areas is determined by subtracting the UTC time hour and the local time zone.

The 24-hour clock does not utilize “am” or “pm,” but rather runs from midnight to 11 p.m. (23 hours).

What is Daylight savings time (DST)?

Daylight Saving Time (DST) is the practice of setting the clocks forward one hour from standard time during the summer months, and back again in the fall (“spring forward, fall back”), in order to make better use of natural daylight.

What is SQL Date Time?

SQL Date is to store data such as years, months, and days. The format for Date/Time values returned by SQL is YYYY-MM-DD hh:mm:ss:zz and it is stored since 1970–01–01 00:00:00:00.

datetime Description

GETDATE()

Using this function, you can specifically extract the current date and time.

Ex: SELECT GETDATE();

CURRENT_TIMESTAMP

This function is used to get the current timestamp of the system.

Get Nafees’s stories in your inbox

Join Medium for free to get updates from this writer.

Eg: SELECT CURRENT_TIMESTAMP;

Date/Time API

The introduction of the new Date/Time API in Java 8 has fixed the following issues in the old Date/Time API.

Not thread safe — The previous date/time API is not string safe. Hence, the developers had to face many problems while using the data. As a workaround, the new Date/Time API is made immutable and has no set methods.

Poor Design — The default date lacked uniformity as its years, months and days started with 1900, 1 and 0 respectively. The previous API had less referenced methods for date operations. But, the new API provides many utility methods for such operations.

Difficult time zone handling — In the old API, developers had to write a lot of code to deal with time zone issues. New APIs are developed keeping domain-specific design in mind.

Joda Date/Time

JODA TIME, an API included in java 8.0 was created by java.org. It offers better classes and has efficient methods to handle dates and times.

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

he java.util.Date class represents date and time in java. It provides constructors and methods to deal with date and time in java.

The java.util.Date class implements Serializable, Cloneable and Comparable<Date> interface. It is inherited by java.sql.Date, java.sql.Time and java.sql.Timestamp interfaces.

After Calendar class, most of the constructors and methods of java.util.Date class has been deprecated. Here, we are not giving list of any deprecated constructor and method.

java.util.Date is not needed if you are working with java 8

Handling dates is a bit challenging because we need to remember the leap seconds, different time zones, etc.

When using java.util.Date class, we should remember about its shortcomings

when working with JDBC we should utilize java.sql.Date class with caution

Local Date Time

Java LocalDateTime class is an immutable date-time object that represents a date-time, with the default format as yyyy-MM-dd-HH-mm-ss.zzz. It inherits object class and implements the ChronoLocalDateTime interface.

Thank You.

Catch Up Next One….

--

--

Nafees
Nafees

Written by Nafees

Undergraduate Student of University of Jaffna || Associate Software Engineer