标签:format code new cal nts exce solr rate blog
solr时间格式是2015-07-06T00:00:00.0Z,所以下面是把当前时间做转换
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd‘T‘HH:mm:ssZ"); //Date d = format.parse(str.replace("Z", " UTC"));//注意是空格+UTC //System.out.println(d); Date date=new Date(); Calendar calendar=Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 1); System.out.println(date); String temp=format.format(date); String hours=format.format(calendar.getTime()); System.out.println(temp); System.out.println(":::"+hours); int end=temp.indexOf("+"); String re=temp.substring(0,end)+"Z"; int end2=hours.indexOf("+"); String re2=hours.substring(0,end2)+"Z"; System.out.println("当前时间"+re); System.out.println("前一小时"+re2); try { System.out.println(format.parse(re.replace("Z", "UTC"))); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
标签:format code new cal nts exce solr rate blog
原文地址:http://www.cnblogs.com/junrong624/p/6035185.html