String oneHoursAgoTime=""; Date dt = new Date(); SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-HH"); Calendar rightNow = Calendar.getInstance(); rightNow.setTime(dt); //rightNow.add(Calendar.DATE, -1); rightNow.add(Calendar.HOUR, -1); Date dt1=rightNow.getTime(); oneHoursAgoTime = sdf.format(dt1); return oneHoursAgoTime;