How to convert epoch to mySQL timestamp in JAVA

java.time With the release of Java SE 8 in March 2014, the outdated and error-prone legacy Date-Time API (java.util Date-Time types and their formatting type, SimpleDateFormat etc.) was supplanted by java.time, the modern Date-Time API*. The following table depicts the mapping of ANSI SQL types with java.time types: ANSI SQL Java SE 8 DATE LocalDate … Read more

How can I convert a Unix timestamp to DateTime and vice versa?

Here’s what you need: public static DateTime UnixTimeStampToDateTime( double unixTimeStamp ) { // Unix timestamp is seconds past epoch DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); dateTime = dateTime.AddSeconds( unixTimeStamp ).ToLocalTime(); return dateTime; } Or, for Java (which is different because the timestamp is in milliseconds, not seconds): public static … Read more