标签:for ati [] led date static class imp 通过
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateTest { public static void main(String[] args) throws ParseException { Date date = new Date(); /* * 把java.util.Date转换为指定格式String */ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateStr = sdf.format(date); System.out.println(dateStr);// System.out.println(sdf1.format(date)); //通过String.format把日期转换为String System.out.println(String.format("%tF %<tT", date)); /* * 把String转换为Date */ Date date1 = sdf.parse(dateStr); System.out.println(date1); } }
标签:for ati [] led date static class imp 通过
原文地址:http://www.cnblogs.com/jonny-xu/p/6533627.html