集册 Java实例教程 使用日历和SimpleDateFormat格式化显示日期

使用日历和SimpleDateFormat格式化显示日期

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

561
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用日历和SimpleDateFormat格式化显示日期

import java.text.SimpleDateFormat;
/**
时 代      J a v a   公   众 号 - nowjava.com 提供 
**/

import java.util.Calendar;


public class Main {


  public static void main(String[] args) {

    // Create new calendar

    Calendar cal = Calendar.getInstance();


    // Create instance of SimpleDateFormat class using pattern

    SimpleDateFormat dateFormatter1 = new SimpleDateFormat("MMMMM dd yyyy");

    String result = null;


    result = dateFormatter1.format(cal.getTime());

    System.out.println(result);


    dateFormatter1.applyPattern("MM/dd/YY hh:mm:ss");

    result = dateFormatter1.format(cal.getTime());

    System.out.println(result);


    dateFormatter1.a
展开阅读全文