如题。用SimpleDateFormat("yyyy-MM-dd:HH")格式化yyyy-MM-dd:HH-mm好像不行,是否要使用string方法截取?
SimpleDateFormat s1 = new SimpleDateFormat("yyyy-MM-dd:HH-mm");
SimpleDateFormat s2 = new SimpleDateFormat("yyyy-MM-dd:HH");
Date d = new Date();
System.out.println(s1.format(d));
System.out.println(s2.format(s2.parse(s1.format(d))));
是否是说输入"yyyy-MM-dd:HH-mm-ss"输出字符串"yyyy-MM-dd:HH"
?
new SimpleDateFormat("yyyy-MM-dd:HH").format(new Date())
是字符串到字符串的转换吧吧
replaceAll("(.*:\d+).*", "$1")
SimpleDateFormat s1 = new SimpleDateFormat("yyyy-MM-dd:HH-mm");
SimpleDateFormat s2 = new SimpleDateFormat("yyyy-MM-dd:HH");
Date d = new Date();
p(s1.format(d));//原始数据
p(s2.format(s2.parse(s1.format(d))));//你要的结果