标签:
public class SimpleDateFormatDemo1 { public static void main(String[] args) throws ParseException { //先实例化SimpleDateFormat SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //实例化Date Date date = new Date(); //Date --- String String timeStr = sdf.format(date); //输出转换后的字符串 System.out.println(timeStr); //2016-04-30 //String --- Date String time = "2016-12-8"; //按照sdf定义格式,解析字符串,转换成date格式 date = sdf.parse(time); //输出转换后的date System.out.println(date); //Thu Dec 08 00:00:00 GMT+08:00 2016 } }
SimpleDateFormatDemo1 Date和String格式的转换
标签:
原文地址:http://www.cnblogs.com/zyjcxc/p/5448902.html