Answer the question
In order to leave comments, you need to log in
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);
Answer the question
In order to leave comments, you need to log in
"17.01.1970 06:37" - isn't that what you want to get, and what does your code return? (Moscow Standard Time)
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 questionAsk a Question
731 491 924 answers to any question