时间格式化02

来源:互联网 发布:网络mr是什么意思啊 编辑:程序博客网 时间:2024/05/17 09:07

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeDemo02 {
 private SimpleDateFormat sdf = null;

 public String getDate() {// 2010-04-22
  this.sdf = new SimpleDateFormat("yyyy-MM-dd");
  String str = this.sdf.format(new Date());
  return str;
 }

 public String getDateTime() {// 2010-04-22 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() {// 2010年04月22日
  this.sdf = new SimpleDateFormat("yyyy年MM月dd日");
  String str = this.sdf.format(new Date());
  return str;
 }

 public String getDateTimeComplete() {// 2010年04月22日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[]) {
  DateTimeDemo02 dt = new DateTimeDemo02();
  System.out.println(dt.getDateTimeComplete());
  System.out.println(dt.getDateTime());
  System.out.println(dt.getDateTimeStamp());
 }
}

原创粉丝点击