当前时间格式化
Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'测试'HH:mm:ss.SSSZ"); SimpleDateFormat df2 = new SimpleDateFormat("YYYY-MM-DD'T'HH:mm:ss.sssZ"); String str = df.format(date); String str1 = df1.format(date); String str2 = df2.format(date); System.out.println(str); System.out.println(str1); System.out.println(str2); 结果: 2020-01-16T10:57:27.901+0800 2020-01-16测试10:57:27.901+0800 2020-01-16T10:57:27.027+0800
当前时间加5分钟
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Calendar nowTime = Calendar.getInstance(); nowTime.add(Calendar.MINUTE, 5); String str3 = sdf.format(nowTime.getTime()); System.out.println(str3); 结果: 2020-01-16T11:02:27.944+0800
其他