public static void main(String[] args) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd a hh:mm:ss "); Date date = new Date(); System.out.println(format.format(date));
}
public static void main(String[] args) { SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 a hh:mm:ss "); Date date = new Date(); System.out.println(format.format(date));
public static void main(String[] args) { SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 a hh:mm:ss "); Date date = new Date(); System.out.println(format.format(date));
再修改、拼接
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd a hh:mm:ss ");
Date date = new Date();
System.out.println(format.format(date));
}
public static void main(String[] args) {
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 a hh:mm:ss ");
Date date = new Date();
System.out.println(format.format(date));
}自己看api啊
时间这东西挺简单的,想怎么操作就怎么操作。import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;public class DateFormat { // 需要日期对象和你要设置的时间,这个以分钟计算的。
private static String getTimeInterval(Date date, int timeInterval) { Calendar cld = Calendar.getInstance();
cld.setTime(date); String dateStr = getCalendarFormat(cld);
cld.add(Calendar.MINUTE, timeInterval);
dateStr += getCalendarFormat(cld);
return dateStr;
} private static String getCalendarFormat(Calendar cld) {
String am_pm = "";
String strFormat = ""; am_pm = cld.get(Calendar.AM_PM) > 0 ? "下午" : "上午";
strFormat = "(yyyy年MM月dd日 " + am_pm + " hh:mm)"; SimpleDateFormat sdf = new SimpleDateFormat(strFormat);
return sdf.format(cld.getTime());
} public static void main(String[] args) {
// 参数是,当前系统时间和60分钟后
System.out.println("从现在到60分钟后的时间:\n" + getTimeInterval(new Date(), 60));
// 参数是,当前系统时间和90分钟后
System.out.println("从现在到90分钟后的时间:\n" + getTimeInterval(new Date(), 90));
}
}
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 a hh:mm:ss ");
Date date = new Date();
System.out.println(format.format(date));
} Calendar
DateUtils