使用Date和SimpleDate
运行结果不显示呀?!
运行结果不显示呀?!
2016-05-15
不显示什么意思,你有输出吗?
public class DateTest { public static void main(String[] args) { SimpleDateFormat fmt = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss"); SimpleDateFormat fmt2 = new SimpleDateFormat("yyyy/MM/dd HH:mm"); SimpleDateFormat fmt3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date now = new Date(); System.out.println(fmt.format(now)); System.out.println(fmt2.format(now)); System.out.println(fmt3.format(now)); String date = "2016-5-15 14:16:21"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); try { Date de = sdf.parse(date); System.out.println(de); } catch (ParseException e) { e.printStackTrace(); } } }
举报