skewen 发表于 2013-2-3 11:35:40

java中时间日期的格式化输出

import java.text.SimpleDateFormat;import java.util.*;public class CalendarDemo { public String getDateTime(){ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss"); Calendar starttime=Calendar.getInstance(); String time=dateFormat.format(starttime.getTime()); return time;}public String getDateString(){ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Calendar starttime=Calendar.getInstance(); String date=dateFormat.format(starttime.getTime()); return date ;}public String getDate(){ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); Calendar starttime=Calendar.getInstance(); String time=dateFormat.format(starttime.getTime()); return time;}public static void main(String [] agrs){ CalendarDemos= new CalendarDemo();System.out.println(s.getDate()); System.out.println(s.getDateString()); System.out.println(s.getDateTime());} http://dl.iteye.com/upload/attachment/245350/9261bb31-4ce5-3e9d-9848-9453e69d7710.png 
页: [1]
查看完整版本: java中时间日期的格式化输出