calendar = Calendar.getInstance(); Date trialTime = new Date(); calendar.setTime(trialTime);calendar.get(Calendar.YEAR); calendar.get(Calendar.DAY_OF_MONTH); 相关属性你自己取好了。
那你设一下format SimpleDateFormat formatter; // Formats the date displayed Date currentDate; // Used to get date to display String date; formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault()); currentDate = new Date(); date = formatter.format(currentDate);
SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-mm-dd"); Date date = new Date(); System.out.println(bartDateFormat.format(date)); 这样出来的时间 年是对的但后面月和日期都是错的
private String ttday() { StringBuffer trudate = new StringBuffer(); Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int dddd = cal.get(Calendar.DATE);
Date trialTime = new Date();
calendar.setTime(trialTime);calendar.get(Calendar.YEAR);
calendar.get(Calendar.DAY_OF_MONTH);
相关属性你自己取好了。
SimpleDateFormat formatter; // Formats the date displayed
Date currentDate; // Used to get date to display
String date; formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault());
currentDate = new Date();
date = formatter.format(currentDate);
Date date = new Date();
System.out.println(bartDateFormat.format(date));
这样出来的时间 年是对的但后面月和日期都是错的
StringBuffer trudate = new StringBuffer();
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int dddd = cal.get(Calendar.DATE);
trudate.append(year);
trudate.append(month);
trudate.append(dddd);
String ttd = trudate.toString();
return ttd;我这样得到的是 2004613 为什么是上个月的?