Avoid the Date object creation w/ System.currentTimeMillis(). A divide by 1000 gets you to Unix epoch.

As mentioned in a comment, you typically want a primitive long (lower-case-l long) not a boxed object long (capital-L Long) for the unixTime variable's type.

long unixTime = System.currentTimeMillis() / 1000L;
Answer from John M on Stack Overflow
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java dates โ€บ retrieving unix time in java
Retrieving Unix Time in Java | Baeldung
January 8, 2024 - In the code above, we create an instance of DateTime with a fixed date and time and invoke the getMillis() method. Next, we divide it by 1000L to get the Unix time timestamp.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java dates โ€บ convert date to unix timestamp in java
Convert Date to Unix Timestamp in Java | Baeldung
February 4, 2024 - In Java, the Date class represents a specific point in time with millisecond precision. It provides one of the easiest ways to convert a date into a Unix timestamp through the getTime() method:
๐ŸŒ
Attacomsian
attacomsian.com โ€บ blog โ€บ java-get-unix-timestamp
How to get the Unix timestamp in Java
October 6, 2022 - In short, a Unix timestamp is the number of seconds between a specific date and the Unix Epoch.
๐ŸŒ
Epoch Converter
epochconverter.com
Epoch Converter - Unix Timestamp Converter
Easy epoch/Unix timestamp converter for computer programmers. Includes epoch explanation and conversion syntax in various programming languages.
๐ŸŒ
ZetCode
zetcode.com โ€บ java โ€บ unixtime
Java Unix time - get Unix time in Java
Java Unix time tutorial shows how to compute Unix time in Java.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java dates โ€บ create date from unix timestamp in java
Create Date From Unix Timestamp in Java | Baeldung
January 8, 2024 - In this quick tutorial, weโ€™ll learn how to parse representations of dates from a Unix timestamp. Unix time is the number of seconds elapsed since January 1, 1970. However, a timestamp can represent time down to nanosecond precision.
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ core java โ€บ java date โ€บ get unix timestamp in java
Get Unix Timestamp in Java - Java2Blog
September 20, 2022 - You can use legacy Dateโ€™s getTime() method to get unix timestamp in Java.
Find elsewhere
๐ŸŒ
w3resource
w3resource.com โ€บ java-exercises โ€บ datetime โ€บ java-datetime-exercise-36.php
Java - Convert a unix timestamp to date
Write a Java program to transform a Unix timestamp into a Date object and format it using SimpleDateFormat.
๐ŸŒ
Medium
medium.com โ€บ @tararamgoyal4_92353 โ€บ how-can-java-get-epoch-time-and-what-is-it-644102fa9083
How can Java get Epoch time, and what is it? | by TARA RAM GOYAL | Medium
July 30, 2023 - Weโ€™ll investigate what epoch time is and how to get it in Java. ... In computer science, the epoch time, often known as Unix time, is the number of seconds from January 1, 1970.
๐ŸŒ
Timestamper
timestamper.online โ€บ guide โ€บ java
Unix Timestamp in Java - Convert, Parse, Format
import java.time.Instant; // Parse ISO string to timestamp long ts = Instant.parse("2024-01-01T00:00:00Z").getEpochSecond();
๐ŸŒ
Quora
quora.com โ€บ Can-I-use-Java-to-create-a-16-digit-epoch-Unix-timestamp-essentially-microseconds-since-January-1-1970
Can I use Java to create a 16 digit epoch/Unix timestamp, essentially microseconds since January 1, 1970? - Quora
Answer (1 of 3): Yes because that is the basis of the Java [code ]Date[/code] class. The [code ]getTime()[/code] method on the Date class returns the number of milliseconds since epoch, January 1, 1970. Date (Java Platform SE 8 )
๐ŸŒ
Sabe
sabe.io โ€บ blog โ€บ java-unix-timestamp
How to get the Unix timestamp in Java
April 8, 2022 - Here's how to get the current time ... want. The original way to get the unix timestamp in Java was to use the System.currentTimeMillis() method....
๐ŸŒ
Unixtime
unixtime.guru โ€บ date-java
Current timestamp. Convert your timestamp to readable date
For format unixtime to human readable date you have two ways: use date() function or DateTime object. $date = date('d-m-Y H:i:s'); // or $date = new DateTime(); $date->setTimestamp($timeStamp); echo $date->format('d-m-Y H:i:s');
๐ŸŒ
O'Reilly
oreilly.com โ€บ library โ€บ view โ€บ java-coding-problems โ€บ 9781789801415 โ€บ b29e67eb-b160-4e6a-b9e3-43a868f97ec6.xhtml
69. Converting a Unix timestamp to date-time - Java Coding Problems [Book]
September 20, 2019 - So, the solution to obtain a Date object from a Unix timestamp requires a conversion from seconds to milliseconds by multiplying the Unix timestamp by 1,000 as shown in the following two examples:
Author ย  Anghel Leonard
Published ย  2019
Pages ย  816
๐ŸŒ
Reddit
reddit.com โ€บ r/clojure โ€บ noob question: how do i convert a unix epoch timestamp to instant/java time?
r/Clojure on Reddit: Noob question: How do I convert a unix epoch timestamp to instant/java time?
February 6, 2021 -

Hi, just started to learn Clojure a couple of weeks ago. Now working on parsing some data, and I got stuck trying to convert epoch time. I'm using java-time for time operations, but it doesn't seem to have any functions to handle a timestamp like this 1612605265.

๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 384000 โ€บ java โ€บ Convert-Unix-TimeStamp-Date-Format
Convert Unix TimeStamp to Date Format (Java in General forum at Coderanch)
Hi, I have this code this is the utput java MyConsoleIO Type some data for the program: 1194560520 input = Wed Jan 07 06:26:51 EST 1970 i should be gettong - Thur Nov 08 2007 17:22 sometin like this Please do help me out here Thanks Vivian Aranha