Linked Questions
17 questions linked to/from How to get milliseconds from LocalDateTime in Java 8
58 votes
3 answers
112k views
Java 8 – Create Instant from LocalDateTime with TimeZone [duplicate]
I have a date stored in the DB in string format ddMMyyyy and hh:mm and the TimeZone. I want to create an Instant based on that information, but I don't know how to do it. something like ...
1 vote
2 answers
21k views
Kotlin LocalDateTime as Long [duplicate]
I am trying to get my LocalDateTime field saved as a long so I can store it in my SQLite database. How am I able to do this? var datetime = LocalDateTime.now() var longdt: Long = getString(datetime)....
1 vote
2 answers
1k views
How to gain milliseconds of LocalTime variable? [duplicate]
Executed piece of code : String lapTime = "27:10.190"; int minutes = Integer.parseInt(lapTime.substring(0, lapTime.indexOf(":"))); int seconds = Integer.parseInt(lapTime.substring(...
1 vote
0 answers
1k views
How to zero out milliseconds using new Date Time API of Java? [duplicate]
I would like to get the date & time now and from that do the following: (i) set the month to the first and (ii) zero out everything after the month (iii) calculate the date 1 year and 1 month ...
0 votes
1 answer
503 views
Java and Arduino, get epoch time independent of time zone [duplicate]
I have an Arduino program that connects to a java web server, and I need to synchronize time. But there is a one hour sync problem. The output of this Java program: public class Test { public ...
-2 votes
0 answers
379 views
Java equivalent of JavaScript Date.UTC [duplicate]
Java equivalent of JavaScript Date.UTC(1980, 0, 8) Example in JavaScript : var base_date = Date.UTC(1980, 0, 8); console.log("base_date:" + base_date) The result is: base_date:316137600000 ...
337 votes
9 answers
347k views
How can I create a Java 8 LocalDate from a long Epoch time in Milliseconds?
I have an external API that returns me dates as longs, represented as milliseconds since the beginning of the Epoch. With the old style Java API, I would simply construct a Date from it with Date ...
63 votes
5 answers
102k views
Convert java.time.Instant to java.sql.Timestamp without Zone offset
In the application I am developing, I need to convert java.time.Instant object to java.sql.Timestamp. When I create Instant object like: Instant now = Instant.now(); I receive something like 2017-03-...
27 votes
3 answers
61k views
Converting a time to milliseconds correctly in java.time (Java 8)
I've been trying to convert a "DateTime" to milliseconds using the java.time package built into Java 8. But I haven't been able to do it correctly. I am trying to convert "29/Jan/2015:18:00:00" to ...
13 votes
2 answers
14k views
Java Best Practice for Date Manipulation/Storage for Geographically Diverse Users
I have read all of the other Q/A about Date Manipulation, but none of them seems to deliver a satisfactory answer to my concern. I have a project with geographically diverse users which uses Date in ...
4 votes
2 answers
2k views
Get epoch time from yesterday in a range of hours
First off I'm new in this incredible community. This is an amazing site. I'm happy to be part finally. Every day I have to insert yesterday's data in the DB. For example, today May 22, I have to ...
-2 votes
1 answer
4k views
How to convert Java LocalDate to milliseconds
I am trying to convert a date formatted in yyyy-mm-dd to LocalDate to milliseconds with this code. LocalDate.parse("2022-08-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")) ...
1 vote
2 answers
2k views
Converting java.sql.timestamp to millisecond format
I have a private java.sql.Timestamp myDate in some model (POJO) class like below private String isActive; private Date dob; private Timestamp createdDate; private Timestamp lastMktPrefUpdateAt; We ...
2 votes
1 answer
2k views
Jackson serialize and Deserialize DateTime From/To WCF DateTime
I use Jackson to serialise and deserialise object. I have .NET WCF DateTime JSON format with Time Zone. And Jackson can't deserialise JSON to object. I found some solutions, but is there any Jackson ...
-1 votes
1 answer
2k views
how to convert microseconds to LocalDateTime in java 8 [duplicate]
I can convert 19 digit unix timestamp to LocalDateTime like this Instant instant = Instant.ofEpochSecond( TimeUnit.NANOSECONDS.toSeconds(timestamp), ...