How to transform currentTimeMillis to a readable date format?
It will work.
long yourmilliseconds = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
Date resultdate = new Date(yourmilliseconds);
System.out.println(sdf.format(resultdate));
How Do I Convert System.currentTimeMillis To Time Format? (HH:MM:SS)
There are some object that you can use to make this more easy, like SimpleDateFormat
and Date
.
First prepare the time in mills:
Long currentTime = System.currentTimeMillis();
Choose your desier format with SimpleDateFormat
:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss");
Create your date object:
Date date = new Date(currentTime);
Apply that format into your date object:
String time = simpleDateFormat.format(date);
Log it:
Log.d(TAG, "onCreate: " + time);
Result:
17:05:73
How to convert currentTimeMillis to a date in Java?
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeStamp);
int mYear = calendar.get(Calendar.YEAR);
int mMonth = calendar.get(Calendar.MONTH);
int mDay = calendar.get(Calendar.DAY_OF_MONTH);
Java System.currentTimeMillis() in Human Readable Format UTC
It may help you. If not get back with problem.
long currentTimeMillis = System.currentTimeMillis();
DateFormat dateFormat = new SimpleDateFormat("yy/MM/dd HH:mm");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = new Date(currentTimeMillis);
String currentTime = dateFormat.format(date);
How to convert milliseconds into a readable date?
Using the library Datejs you can accomplish this quite elegantly, with its toString
format specifiers: http://jsfiddle.net/TeRnM/1/.
var date = new Date(1324339200000);
date.toString("MMM dd"); // "Dec 20"
Convert timestamp in milliseconds to string formatted time in Java
Try this:
Date date = new Date(logEvent.timeSTamp);
DateFormat formatter = new SimpleDateFormat("HH:mm:ss.SSS");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String dateFormatted = formatter.format(date);
See SimpleDateFormat for a description of other format strings that the class accepts.
See runnable example using input of 1200 ms.
How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Easy way to get a readable date from a long (timestamp) in scala
You can use the java.time
library like:
val formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")
formatter.format(LocalDateTime.now)
If you only have the timestamp, this solution gets a bit more complex:
formatter.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(System.currentTimeMillis()), ZoneId.of("UTC")))
Then I would take java.text.SimpleDateFormat
:
new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(System.currentTimeMillis())
To get back to the Timestamp:
new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse( "02/12/2012 12:23:44" ).getTime
how to convert milliseconds to date format in android?
Just Try this Sample code:-
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Test {
/**
* Main Method
*/
public static void main(String[] args) {
System.out.println(getDate(82233213123L, "dd/MM/yyyy hh:mm:ss.SSS"));
}
/**
* Return date in specified format.
* @param milliSeconds Date in milliseconds
* @param dateFormat Date format
* @return String representing date in specified format
*/
public static String getDate(long milliSeconds, String dateFormat)
{
// Create a DateFormatter object for displaying date in specified format.
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
// Create a calendar object that will convert the date and time value in milliseconds to date.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(milliSeconds);
return formatter.format(calendar.getTime());
}
}
Related Topics
Unhandled Exception Type Error
How to Delete Files Programmatically on Android
How to Draw an Arrowhead (In Android)
How to Implement the Android Actionbar Back Button
How to Avoid Unnecessary Firestore Reads with Cache
How to Override the Cipherlist Sent to the Server by Android When Using Httpsurlconnection
Why Does My Compare Method Throw Exception -- Comparison Method Violates Its General Contract!
Java Client and a C++ Server Send and Receive via Tcp Socket
Curly Braces in "New" Expression? (E.G. "New Myclass() { ... }")
Fragment Add or Replace Not Working
Eclipse: Jvm Terminated. Exit Code=2
Should I Strictly Avoid Using Enums on Android
Kotlin-Android: Unresolved Reference Databinding