1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java秒转换为年月日_java时间转化为年月日以及将秒转化为天小时分秒字符串显示总结...

java秒转换为年月日_java时间转化为年月日以及将秒转化为天小时分秒字符串显示总结...

时间:2019-08-09 04:13:35

相关推荐

java秒转换为年月日_java时间转化为年月日以及将秒转化为天小时分秒字符串显示总结...

注意:php的后台的时间按照秒计算,android按照毫秒计算,所以时间

String getstrtime = Tool.getNormalTime(Long.parseLong(time + "000"));

time是php后台的秒为单位的时间是十位数,android前台显示需要转化为毫秒计算是13位数补加三个0

1 时间转化为年月日小时分秒:

public static String getNormalTime(long value) {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;

String time = format.format(new Date(value)) ;

return time;

}

2 时间转化为小时和秒

public static String getNormalHMTime(long value) {

SimpleDateFormat format = new SimpleDateFormat("HH:mm") ;

String time = format.format(new Date(value)) ;

return time;

}

3 时间转化为年月日

public static String getNormalYMDTime(long value) {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd") ;

String time = format.format(new Date(value)) ;

return time;

}

4 时间秒转化为多少天小时分秒

/**

* 秒转化为天小时分秒字符串

*

* @param seconds

* @return String

*/

public static String formatSeconds(long seconds) {

String timeStr = seconds + "秒";

if (seconds > 60) {

long second = seconds % 60;

long min = seconds / 60;

timeStr = min + "分" + second + "秒";

if (min > 60) {

min = (seconds / 60) % 60;

long hour = (seconds / 60) / 60;

timeStr = hour + "小时" + min + "分" + second + "秒";

if (hour > 24) {

hour = ((seconds / 60) / 60) % 24;

long day = (((seconds / 60) / 60) / 24);

timeStr = day + "天" + hour + "小时" + min + "分" + second + "秒";

}

}

}

return timeStr;

}

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