Java 在android中,将当前时间增加1小时
可能重复:Java 在android中,将当前时间增加1小时,java,android,calendar,Java,Android,Calendar,可能重复: 我正在使用此代码获取当前日期和时间 SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd:HH:mm"); String currentDateandTime = sdf.format(new Date()); System.out.println("current time date" + currentDateandTime); 现在我想再加上一个小时。我搜索了一下,但没有得到我想要的答案。现在我是这样的: curre
我正在使用此代码获取当前日期和时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd:HH:mm");
String currentDateandTime = sdf.format(new Date());
System.out.println("current time date" + currentDateandTime);
现在我想再加上一个小时。我搜索了一下,但没有得到我想要的答案。现在我是这样的:
current time date2012:12:13:12:05
我想要一个24小时格式的答案,如2012:12:13:13:05
。试试:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd:HH:mm");
String currentDateandTime = sdf.format(new Date());
Date date = sdf.parse(currentDateandTime);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, 1);
System.out.println("Time here "+calendar.getTime());
在将日期传递给sdf.format(date)之前,可以这样递增日期 看看这会帮你确定。。。
Date a=new Date();
a.setTime(System.currentTimeMillis()+(60*60*1000));
Calendar now = Calendar.getInstance();
now.add(Calendar.HOUR,1);
System.out.println(now.getTime());