java学习之Date的使用

Date使用,主要要注意将日期格式化,否则返回的是系统默认的格式。请自己查阅API文档。

import java.util.*;
import java.text.*;
public class TestDate
{
	public static void main(String[] args)
	{
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat ("yyy-MM-DD hh:ss:mm");
  //格式可以根据需要自己改,SimpleDateFormat方法就是将系统日期格式更改为想要的格式。
String s = sdf.format(date); System.out.println(date); System.out.println(s); } }
posted @ 2013-08-25 23:06  shoneworn  阅读(489)  评论(1编辑  收藏  举报