失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android将毫秒转换成日期 如何在Android中将毫秒转换为日期格式?

android将毫秒转换成日期 如何在Android中将毫秒转换为日期格式?

时间:2023-03-15 23:40:38

相关推荐

android将毫秒转换成日期 如何在Android中将毫秒转换为日期格式?

只需尝试以下示例代码:-

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

}

}

希望对您有帮助...

如果觉得《android将毫秒转换成日期 如何在Android中将毫秒转换为日期格式?》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。