V
V
Vanes Ri_Lax2015-08-06 12:15:24
Java
Vanes Ri_Lax, 2015-08-06 12:15:24

How to convert timestamp to format dd.MM.yyyy?

Hello, I've seen similar threads here but haven't found an answer yet.
In general, I have a String type variable that has the value 1438628700
I need to translate this value into a readable date type dd.MM.yyyy hh:mm
I tried to do it like this:

String s = "1438628700";
Date d = new Date(Long.valueOf(s));
 
        SimpleDateFormat formatDate = new SimpleDateFormat("dd.MM.yyyy hh:mm");
        String formatted = formatDate.format(d);
 
        System.out.println(formatted);

But my conclusion was, of course, incorrect. Further, after converting to Long, I multiplied the result by 1000, I got a normal time, but the hours and minutes were different.
How can I solve this problem, thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Goncharov, 2015-08-06
@andre_goncharov

"17.01.1970 06:37" - isn't that what you want to get, and what does your code return? (Moscow Standard Time)

D
da_42, 2015-08-09
@da_42

You can take a calendar class, set a timestamp in it (multiplying by 1000 to get millisec.) and get all the necessary fields from the calendar - day, month, etc.

Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp * 1000);
Log.i(TAG, "дата: " + cal.get(Calendar.DAY_OF_MONTH) ... );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question