zoukankan      html  css  js  c++  java
  • Time Format Example

    This example shows how to format time using Format class. In this program we use a pattern of special characters to time format.

    Time Format Example

         

    This example shows how to format time using Format class. In this program we use a pattern of special characters to time format.

    Description of the code :

    SimpleDateFormat() : SimpleDateFormat class use for formatting and parsing dates. It allows for formatting date into text , parsing text into date and normalization.

    format() : This method used for format Date class object into date / time and appends the it into the StringBuffer.

    TimeFormat.java


    import java.text.*;
    import java.util.*;

    public class TimeFormat {

      public static void main(String args[]) {

      String s;
      Format formatter;
      Date date = new Date();

      // Time formate 01:12:53 AM
      formatter = new SimpleDateFormat("hh:mm:ss a");
      s = formatter.format(date);
      System.out.println("hh:mm:ss a formate : " + s);

      //Time formate 14.36.33
      formatter = new SimpleDateFormat("HH.mm.ss");
      s = formatter.format(date);
      System.out.println("HH.mm.ss : formate : " + s);
      }
    }



    Output

    hh:mm:ss a formate : 04:31:16 PM
    HH.mm.ss : formate : 16.31.16
  • 相关阅读:
    结对练习(能力有限,待解决......)
    骰子修改
    骰子传奇
    现在的辛苦一点,会是将来的更好一点!
    入坑?那就从坑里爬出来
    性能测试工具locust简单应用
    阿里云环境部署
    Charles的安装与抓取手机包设置
    windows常用命令-netstat
    采坑小记——adb链接夜神模拟器
  • 原文地址:https://www.cnblogs.com/lexus/p/2291602.html
Copyright © 2011-2022 走看看