java12小时制的时间转换为24小时制


import java.text.SimpleDateFormat;
import java.util.Date;
 
public class ceshi {
    public static void main(String[] args) {
        SimpleDateFormat objSDateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");//转换为24小时制
        String strCurrentTime = objSDateFormat.format(new Date());
        System.out.println(strCurrentTime);
    }
 
}

大写的HH为24小时制,小写的hh为12小时制。

在ss的后面加上 a,这样可以在后面显示上下午:显示效果为“2019-03-24 17:00:14 下午”


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM