zoukankan      html  css  js  c++  java
  • Java如何格式化24小时格式的时间?

    在Java中,如何格式化24小时格式的时间??

    此示例使用SimpleDateFormat类的sdf.format(date)方法将时间格式化为24小时格式(00:00-24:00)。

    package com.yiibai;
    
    import java.text.SimpleDateFormat;
    import java.util.*;
    
    public class FormatTimeIn24Hour {
        public static void main(String[] args) {
            // 示例1
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("h");
            System.out.println("hour in h format : " + sdf.format(date));
    
            // 示例2
            Date d2 = new Date();
            SimpleDateFormat simpDate2;
            simpDate2 = new SimpleDateFormat("kk:mm:ss");
            System.out.println(simpDate2.format(d2));
    
            // 示例3
            Date d3 = new Date();
            SimpleDateFormat simpDate3;
            simpDate3 = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
            System.out.println(simpDate3.format(d3));
    
        }
    }
    
    Java

    上述代码示例将产生以下结果,结果将根据当前系统时间而有变化。

    hour in h format : 20
    20:43:15
    2017-09-17 20:43:15
  • 相关阅读:
    CTK 编译
    MITK 2021.2编译
    执行git add .报错LF will be replaced by CRLF in
    vscode标记“&&”不是此版本中的有效语句分隔符
    vscode prettier插件使用无效
    vscode使用技巧
    kafka及hdfs常用命令
    博客已迁移
    SVM
    逻辑回归
  • 原文地址:https://www.cnblogs.com/borter/p/9613397.html
Copyright © 2011-2022 走看看