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

本文提供了几种时间格式转换的方法,包括从秒到毫秒的转换、时间戳到日期格式的转换等。适用于PHP后台与Android前台间的时间同步问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

注意: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;  
    }  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值