注意: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;
}
本文提供了几种时间格式转换的方法,包括从秒到毫秒的转换、时间戳到日期格式的转换等。适用于PHP后台与Android前台间的时间同步问题。
4万+

被折叠的 条评论
为什么被折叠?



