Converting Unix timestamp to Date Time String [duplicate]

Active3 hr before
Viewed126 times

6 Answers


You can use SimlpeDateFormat to format your date like this:,Because a Date provides a getTime() method that returns the milliseconds since EPOC, it is required that you give to SimpleDateFormat a timezone to format the date properly acording to your timezone, otherwise it will use the default timezone of the JVM (which if well configured will anyways be right),Java 8 introduces the Instant.ofEpochSecond utility method for creating an Instant from a Unix timestamp, this can then be converted into a ZonedDateTime and finally formatted, e.g.:, 1 private String getDateString(long timeInMilliseconds) { SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z"); return formatter.format(timeInMilliseconds); } – JVJplus Jan 6 '20 at 18:33

You can use SimlpeDateFormat to format your date like this:

long unixSeconds = 1372339860;
// convert seconds to milliseconds
Date date = new java.util.Date(unixSeconds * 1000 L);
// the format of your date
SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
// give a timezone reference for formatting (see comment at the bottom)
String formattedDate = sdf.format(date);
load more v

const unixTime = 1210981217;
const date = new Date(unixTime * 1000);
//expected: "5/16/2008"
load more v

Write a Python program to convert unix timestamp string to readable date.,Python Pandas exercises,Python BeautifulSoup exercises,Python Itertools exercises

Python Code:

import datetime
   ).strftime('%Y-%m-%d %H:%M:%S')

Sample Output:

2010 - 09 - 10 13: 31: 22
load more v

How do you convert a Unix timestamp value into a human-readable date using vanilla JavaScript?,You now know how to convert a Unix timestamp into a human-readable date using vanilla JavaScript!,Convert the Unix Timestamp to Milliseconds,So, let's write some code to convert a Unix timestamp to milliseconds:

    const unixTimestamp = 1575909015

    const milliseconds = unixTimestamp * 1000 // 1575909015000
load more v

Here is the java utility service to convert Epoch Time to Simple Date Time Format. Create a java service "GetDateTimeByEpoch" and define the below input and output, copy-paste the code as provided below, add the required imports:

Output: dateTimeStamp (String)

=== === === === === === === === === === === === === === === === =

import java.util.Locale;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;

=== === === === === === === === === === === === === === === =

IDataCursor pipelineCursor = pipeline.getCursor();

String epochTime = (String) IDataUtil.get(pipelineCursor, "epochTime");

//long unix_seconds = 1563370941;  

long unix_seconds = Long.parseLong(epochTime);

//convert seconds to milliseconds

Date date = new Date(unix_seconds * 1000 L);

// format of the date  

SimpleDateFormat jdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String java_date = jdf.format(date);

//System.out.println("\n" + java_date + "\n");

IDataUtil.put(pipelineCursor, "dateTimeStamp", java_date);


My server is returning a timestamp 1322400600 in String, In my android application, i need to convert it like Nov 27, 2011 07:00am. I don't know how to do this please help me out.,Possible Duplicate: Converting Timestamp as String to Date in android ,You can use new java.util.Date(Long.parseLong(timeInMillis)). With this Date object there are several ways to extract the date in your desired String format, the simplest way using Date.toString(). Alternatively, and more appropriately you can use a SimpleDateFormat with the exact pattern you want.

I used following code to get the desired value

long dv = Long.valueOf(timestamp_in_string) * 1000; // its need to be in milisecond
Date df = new java.util.Date(dv);
String vv = new SimpleDateFormat("MM dd, yyyy hh:mma").format(df);
load more v

Other "string-timestamp" queries related to "Converting Unix timestamp to Date Time String [duplicate]"