How to Transform Currenttimemillis to a Readable Date Format

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



Leave a reply



Submit