`
daichangfu
  • 浏览: 264310 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

获取今天距离指定时间还有几天几时几分几秒

    博客分类:
  • java
 
阅读更多
	/**
	 * 获取今天还剩下多少秒
	 * @return
	 */
	public static int getMiao(){
		Calendar curDate = Calendar.getInstance();
		Calendar tommorowDate = new GregorianCalendar(curDate
				.get(Calendar.YEAR), curDate.get(Calendar.MONTH), curDate
				.get(Calendar.DATE) + 1, 0, 0, 0);
		return (int)(tommorowDate.getTimeInMillis() - curDate.getTimeInMillis()) / 1000;
	}
	
	/**
	 * 获取今天距离指定时间还有多久
	 * @return
	 */
	public static String getSjc(Date date){
		Calendar curDate = Calendar.getInstance();
		Calendar tommorowDate = Calendar.getInstance();
		tommorowDate.setTime(date);
		long miao = (tommorowDate.getTimeInMillis() - curDate.getTimeInMillis())/1000;
		int day = (int)(miao / (60*60*24));				//天
		int hour = (int)(miao % (60*60*24) / (60*60));	//时
		int mm = (int)(miao % (60*60) / 60);			//分
		int sec = (int)(miao % 60);						//秒
		return day+"天"+hour+"时"+mm+"分"+sec+"秒";
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics