集册 Java实例教程 使用SimpleDateFormat以自定义格式格式化日期

使用SimpleDateFormat以自定义格式格式化日期

欢马劈雪     最近更新时间:2020-01-02 10:19:05

374
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用SimpleDateFormat以自定义格式格式化日期

 

import java.util.Date;

import java.text.SimpleDateFormat;

 /**来自 NowJava.com - 时  代  Java**/

public class Main {

  public static void main(String[] args) {

    Date date = new Date();

 

    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");

    String strDate = sdf.format(date);

    System.out.println("formatted date in mm/dd/yy : " + strDate);

   

    sdf = new SimpleDateFormat("dd/MM/yyyy");

    strDate = sdf.format(date);

    System.out.println("formatted date in dd/MM/yyyy : " + strDate);

   

    sdf = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");

    
展开阅读全文