Epoch Time, Credits: epochConverter

Epoch Time in Java

Development & UX Researches
2 min readJul 19, 2020

--

The Unix epoch is the number of seconds that have elapsed since January 1, 1970 midnight UTC/GMT, not counting leap seconds. So the Unix time system describes a point in time.

In Java programming, date conversion between human-readable and program language conversion is necessary most of the cases. Because Unix time is a single signed number that increments every second, which makes it easier for computers to store and manipulate than conventional date systems. Interpreter programs can then convert it to a human-readable format.

When it is necessary to do the conversions;

//How to get the current epoch time in …long epochCurrentTime = System.currentTimeMillis()/1000;
System.out.println(epochCurrentTime);
//Convert from human-readable date to epochlong dateToEpoch = new java.text.SimpleDateFormat(“MM/dd/yyyy HH:mm:ss”).parse(“07/07/2020 01:00:00”).getTime() / 1000;
System.out.println(dateToEpoch);
//Convert from epoch to human-readable dateString epochToDate = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (epoch*1000));
System.out.println(epochToDate);

In the time calculation, leap seconds are ignored, with a leap second having the same Unix time as the second before it, and every day is treated as if it contains exactly 86400 seconds. Due to this treatment, Unix time is not a true representation of UTC. So you might ask, ‘A day is 24 hours clock, exactly?’

*A leap second is a one-second adjustment that is occasionally applied to Coordinated Universal Time, to accommodate the difference between precise time and imprecise observed solar time. The accommodation is measured by atomic clocks.

Matrix Binary Code Wall Clock, Credits: Alex Gheorghe

How Does an Atomic Clock Work?

Atomic clocks are designed to measure the precise length of a second, the base unit of modern timekeeping. The International System defines the second as the time it takes a cesium-133 atom in a precisely defined state to oscillate exactly: 9 billion, 192 million, 631 thousand, 770 times. With an error of only 1 second in up to 100 million years, atomic clocks are among the most accurate timekeeping devices in history.

Why Do We Need Atomic Clocks Anyway?

Even though Scientists are developing Optical Clocks to measure the time more accurately, Atomic Clocks are the most sensitive and accurate devices to measure the time. Satellite navigation systems like GPS also rely on precise time measurements to calculate positions accurately. If you check history, there are many space crafts accidents, such as satellites and Mars mission robots, just because of time calculation errors.

Resources: -wikipedia, -timeanddate

--

--

Development & UX Researches
Development & UX Researches

Written by Development & UX Researches

A self-learner in the programming and UX industry. Keep yourself updated in this journey together ;)