日期类及其格式化程序(在实际中的运用)

一、在日常中会大量使用日期类,取出日期的操作

形式一:2012-11-07

形式二:2012-11-0707:08:26.236

形式三:2012年11月07日

形式四:2012年11月07日 07时08分26秒236毫秒

package org.lxh.dateformatdemo; 

import java.text.SimpleDateFormat;

import java.util.Date; 

public class DateTime {

       private SimpleDateFormat sdf = null;

       public String getDate() {//2009-03-02

              this.sdf = new SimpleDateFormat("yyyy-MM-dd");

              String str = this.sdf.format(new Date());

              return str;

       }

       public String getDateTime() {// 2009-03-02 16:19:34.123

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

              String str = this.sdf.format(new Date());

              return str;

       }

       public String getDateComplete() {//2009年03月02日

              this.sdf = new SimpleDateFormat("yyyy年MM月dd日");

              String str = this.sdf.format(new Date());

              return str;

       }

       public String getDateTimeComplete() {//2009年03月02日16时19分34秒123毫秒

              this.sdf = new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒SSS毫秒");

              String str = this.sdf.format(new Date());

              return str;

       }

       public String getDateTimeStamp(){

              this.sdf = new SimpleDateFormat("yyyyMMddhhmmssSSS");

              String str = this.sdf.format(new Date());

              return str;

       }

       public static void main(String args[]) {

              DateTime dt = new DateTime() ;

              System.out.println(dt.getDateTimeComplete());

              System.out.println(dt.getDateTime());

              System.out.println(dt.getDateTimeStamp());

       }

}

转载于:https://www.cnblogs.com/jiechn/archive/2012/11/13/2768912.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值