What is this date time format? How to convert it into a human readable output? Why it returns this output?

Abdelrahman Ashref :

I'm developing an android application and I use GSON to get the data from the server, I'm working on both APIs of Facebook and Imgur and the same issue happens. How can I convert a date from milliseconds format to a human-readable format like for example 1584780523 and I want to convert it to any format, for example, 25, Mar 2020.

What I tried to do!

Get Data

@SerializedName("datetime")
    @Expose
    private long datetime;

    // setters and getters

In my adapter after getting DATETIME I parse it to a human-readable format

// Get Datetime. 
long getDate = data.getDatetime();

// Parse it in this format for example.
DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss:SSS Z");
Date result = new Date(getDate);

// Set Result (Human-Readable date)
date.setText(dateFormat.format(result));

But here is the problem! It gives me date like this

19 Jan 1970 09:54:00:533 +0200

Why the output at the 1970s. I saw something like that is the default output of Datetime? But in the same case, it gives me on the other items on my RecyclerView the same output but the last three digits changes!

Here what I'm asking!

1- Why we use (a lot of people use long instead of int?

2- Why the output gives me that and how can I fix this?

3- In other APIs like Youtube they use the regular DateTime why Facebook and Imgur changes them?

Note: I searched about my question for 3 days but I didn't get any answers or relative questions on StackOverflow so, I asked here. All of them or most are for PHP and JavaScript I need an example in Java Android Studio

Thanks.

Andreas :

Your 1584780523 value is in seconds, not milliseconds.

long secondsSinceEpoch = 1584780523;
long millisSinceEpoch = secondsSinceEpoch * 1000L;
Date date = new Date(millisSinceEpoch);
System.out.println(date);

SimpleDateFormat fmt = new SimpleDateFormat("d, MMM yyyy", Locale.US);
System.out.println(fmt.format(date));

Output1

Sat Mar 21 04:48:43 EDT 2020
21, Mar 2020

1) I'm in America/New_York time zone

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to convert time date from JSON to human readable?

分類Dev

Ping output - epoch time to human readable

分類Dev

Convert date from human readable format golang

分類Dev

Convert Bigint data to human readable date-time in Sql

分類Dev

convert escaped unicode sequence to human readable format

分類Dev

Javascript: Convert timestamp to human readable date?

分類Dev

How do I convert API supplied date/time string into readable format?

分類Dev

Cannot convert 16 digit number to human readable date

分類Dev

How to change date format and position in find output

分類Dev

How to format date output with spaces as variable in script?

分類Dev

python - convert date input to date output without time

分類Dev

Timestamp to human readable date with angular

分類Dev

What is this date and time format?

分類Dev

SQL Date format with HTML output

分類Dev

How to convert string to dig readable format rails?

分類Dev

how to convert python time.time() to date format for sql insertion

分類Dev

How to format the given time string and convert to date/time object

分類Dev

How to format arp -a output?

分類Dev

Machine readable pstree output?

分類Dev

How to Get Date only or Time only output in react-native

分類Dev

What is datetime object in Google API, and how to format its string output?

分類Dev

Human readable dmesg time stamps on OpenWRT

分類Dev

Convert GMT date format to only time format

分類Dev

Why is `--human-readable` needed and not default?

分類Dev

Convert output of tree command to json format

分類Dev

`stat` output format: truncate a date field

分類Dev

How does this recursive function resolve and why does it output what it does

分類Dev

Controlling Excel time format input/output

分類Dev

time and date functions gives wrong output in php

Related 関連記事

  1. 1

    How to convert time date from JSON to human readable?

  2. 2

    Ping output - epoch time to human readable

  3. 3

    Convert date from human readable format golang

  4. 4

    Convert Bigint data to human readable date-time in Sql

  5. 5

    convert escaped unicode sequence to human readable format

  6. 6

    Javascript: Convert timestamp to human readable date?

  7. 7

    How do I convert API supplied date/time string into readable format?

  8. 8

    Cannot convert 16 digit number to human readable date

  9. 9

    How to change date format and position in find output

  10. 10

    How to format date output with spaces as variable in script?

  11. 11

    python - convert date input to date output without time

  12. 12

    Timestamp to human readable date with angular

  13. 13

    What is this date and time format?

  14. 14

    SQL Date format with HTML output

  15. 15

    How to convert string to dig readable format rails?

  16. 16

    how to convert python time.time() to date format for sql insertion

  17. 17

    How to format the given time string and convert to date/time object

  18. 18

    How to format arp -a output?

  19. 19

    Machine readable pstree output?

  20. 20

    How to Get Date only or Time only output in react-native

  21. 21

    What is datetime object in Google API, and how to format its string output?

  22. 22

    Human readable dmesg time stamps on OpenWRT

  23. 23

    Convert GMT date format to only time format

  24. 24

    Why is `--human-readable` needed and not default?

  25. 25

    Convert output of tree command to json format

  26. 26

    `stat` output format: truncate a date field

  27. 27

    How does this recursive function resolve and why does it output what it does

  28. 28

    Controlling Excel time format input/output

  29. 29

    time and date functions gives wrong output in php

ホットタグ

アーカイブ