GregorianCalendar calendar = new GregorianCalendar();
String sdt = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DATE);
这个是得到类似于yyyy-mm-dd的时间格式,相信你能看出如何写出你要的格式了。
String sdt = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DATE);
这个是得到类似于yyyy-mm-dd的时间格式,相信你能看出如何写出你要的格式了。
然后使用Calendar中的方法就可以了。
String time=formatter.format(new Date());//得到当前时间
String dateTime = "";
Date sysDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
StringBuffer tb = new StringBuffer();
dateTime = sdf.format(sysDate , tb, new FieldPosition(0)).toString();
return dateTime;
}
jackkui(键盘上的武士)的回复是最为简捷的方法,
楼主使用的方法在1.4版本之后已经不支持了。
extends Object
implements Serializable, Cloneable, Comparable<Calendar>The Calendar class is an abstract class that provides methods for converting between a specific instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on, and for manipulating the calendar fields, such as getting the date of the next week. An instant in time can be represented by a millisecond value that is an offset from the Epoch, January 1, 1970 00:00:00.000 GMT (Gregorian).