怎么用日期格式化函数生成这样的字符串
2008年11月28日 上午10:00 - 11:30
2008年11月28日 上午10:00 - 11:30
解决方案 »
- 整型转为字节数组后地址顺序发生了变化,为什么?
- java 如何取得图片的宽度,厘米而非象素
- Struts2 action中的execute不执行
- 请教高手一个JAVA显示图形的问题!!!!!!!!!!!!!!!!!!!!!
- 有关字体及图形的问题!!!!!!!!!!!!!1
- ****>>绝对挑战<<**** 期待高手中的高手:c++利用jni调用java,已经能调用了,但不能连
- 求解一道面试题啊~~~~~~
- JAVA异常抛出机制
- 请教定义实体类的问题
- Java ServerSocket编程,我为什么接收不到数据?
- 泛型问题
- jtable已經有JTextField和JComboBox等的celleditor 如果想再用鼠標監聽這個table 該怎么做?
再修改、拼接
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