Converting Epoch time to date string
Look into SimpleDateFormat
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
sdf.format(new Date(myTimeAsLong));
Convert epoch String to Java date
I think you're overthinking about the DateFormat
. If I want to simply obtain a Date
instance, what I would try is the following:
Date d = new Date(Long.parseLong(dateString));
how to convert unix epoch time to date string in hive
Oof, that looks ugly. Try using this function in Hive:
SELECT from_unixtime(unix_timestamp) as new_timestamp from raw_data ...
Or if timestamp is in ms
instead of seconds:
SELECT from_unixtime(unix_timestamp DIV 1000) as new_timestamp from raw_data ...
That converts a unix timestamp into a YYYY-MM-DD HH:MM:SS format, then you can use the following functions to get the year, month, and day:
SELECT year(new_timestamp) as year, month(new_timestamp) as month, day(new_timestamp) as day ...
Converting epoch time to a date in time zone in python
1565475300 this is 2019-08-10 22:15:00 in UTC
datetime.fromtimestamp(1565475300, tz=timezone.utc)
datetime.datetime(2019, 8, 10, 22, 15, tzinfo=datetime.timezone.utc)
so it is 23:15 in London time zone
convert epoch time to date
EDIT: Okay, so you don't want your local time (which isn't Australia) to contribute to the result, but instead the Australian time zone. Your existing code should be absolutely fine then, although Sydney is currently UTC+11, not UTC+10.. Short but complete test app:
import java.util.*;
import java.text.*;
public class Test {
public static void main(String[] args) throws InterruptedException {
Date date = new Date(1318386508000L);
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
format.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
String formatted = format.format(date);
System.out.println(formatted);
format.setTimeZone(TimeZone.getTimeZone("Australia/Sydney"));
formatted = format.format(date);
System.out.println(formatted);
}
}
Output:
12/10/2011 02:28:28
12/10/2011 13:28:28
I would also suggest you start using Joda Time which is simply a much nicer date/time API...
EDIT: Note that if your system doesn't know about the Australia/Sydney
time zone, it would show UTC. For example, if I change the code about to use TimeZone.getTimeZone("blah/blah")
it will show the UTC value twice. I suggest you print TimeZone.getTimeZone("Australia/Sydney").getDisplayName()
and see what it says... and check your code for typos too :)
convert epoch time to time string upon receiving query result in angular type script
If you inject the date pipe into your code where you want to do this,
you can map over the array, and invoke the pipe's transform
method for each value, e.g.
const data: Data[] = this.response.map( (datum) =>
{
return {
date: this.datePipe.transform(datum.epoch),
name: datum.name,
status: dataum.status
};
}
);
Converting epoch timestamp into a readable date
That epoch is in seconds, you need to multiply it by 1000.
Related Topics
Date Format Conversion Android
Android:Save a Bitmap to Bmp File Format
Android Studio Mailto Intent Doesn't Show Subject and Mail Body
Android Gps Incorrect Location Data on Query
Why Does My Compare Method Throw Exception -- Comparison Method Violates Its General Contract!
Trivial: Get Confirmation of Email Sent in Android
Pdfbox:Pdpagecontentstream's Append Mode Misbehaving
How to Install "Android Support Library" to Deploy a Gluon Mobile Application to Android
Aes Gcm Implementation with Authentication Tag in Java
How to Install Rjava in R 3.0 in Ubuntu 13.04
How to Run an R Program from Java
Java Object Analogue to R Data.Frame
Libjvm.So: Cannot Open Shared Object File: No Such File or Directory
Loading Data Bigger Than the Memory Size in H2O
How to Remove Specific Permission When Build Android App with Gradle