如何毫秒日期格式转换的机器人?机器人、格式转换、日期

2023-09-11 20:35:18 作者:丝丝情愁

我有毫秒。 我需要它转换为日期格式

I have milliseconds. I need it to be converted to date format of

例如:

23/10/2011

23/10/2011

如何实现的呢?

任何帮助,真是AP preciated。

any help is really appreciated.

推荐答案

只是试试这个样品code: -

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());
}
}

我希望这帮助...

I hope this help...