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

Java中将12小时制的时间转换为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,这样可以在后面显示上下文:显示效果为“2008-03-24 17:00:14 下午”

猜你喜欢

转载自www.cnblogs.com/huangjinyong/p/9258208.html