Java

How to Convert 13 Digit Timestamp to datetime Java

0
Timestamp to datetime Java

Today we are going to see how to Convert 13 Digit Timestamp to datetime Java. Converting a timestamp to datetime is quite easy if you are aware of Java.

If you can use Java 8’s new Time API, then you can create an instant and convert that it to the desired datetime (your computer time zone in my example below):

Instant instant = Instant.ofEpochMilli(millis);
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println(fmt.format(instant.atZone(ZoneId.systemDefault())));

Below we are converting a UNIX timestamp to date Java

import java.util.*;
import java.text.*;

public class Exercise36 {
public static void main(String[] args)
{
//Unix seconds
long unix_seconds = 1372339860;
//convert seconds to milliseconds
Date date = new Date(unix_seconds*1000L);
// format of the date
SimpleDateFormat jdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
jdf.setTimeZone(TimeZone.getTimeZone("GMT-4"));
String java_date = jdf.format(date);
System.out.println("\n"+java_date+"\n");
}
}

There are few other methods which we can use to convert the timestamp to datetime in java which we will be updating shortly.

Top 10 Email Marketing Plugins You Can Try Out Today For Best Results

Previous article

Crop Thumbnail Images in WordPress

Next article

You may also like

Comments

Leave a reply

Your email address will not be published. Required fields are marked *

More in Java