• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

cynchanpin

  • 博客园
  • 联系
  • 订阅
  • 管理

View Post

java 日期和字符串互转,依据当天整天时间 得到当天最后一秒的日期时间

java 日期和字符串互转。依据当天整天时间   得到当天最后一秒的日期时间


package com.hi;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * 依据当天整天时间
 * 得到当天最后一秒
 * 数据库查询时非常有意义         起始天 到结速天  比方按天查询 2014-06-17 00:00:00  到2014-06-20:23:59:59
 * 
 * @author Administrator
 *
 */
public class Main3 {
	
	public static void main(String[] args) throws ParseException 
	{
		DateFormat format=new SimpleDateFormat("yyyy-MM-dd");
		Date d=new Date();
		String str=format.format(d);
		System.out.println(str);
		Date d2=format.parse(str);
		System.out.println(d2);
		/////////////////得到想要測试的时间整天 
		
		
		int dayMis=1000*60*60*24;//一天的毫秒-1
		System.out.println("一天的毫秒-1:"+dayMis);
		
		//返回自 1970 年 1 月 1 日 00:00:00 GMT 以来此 Date 对象表示的毫秒数。
		long curMillisecond=d2.getTime();//当天的毫秒
		System.out.println("curMillisecond:"+new Date(curMillisecond));
		
		long resultMis=curMillisecond+(dayMis-1); //当天最后一秒
		System.out.println("resultMis:"+resultMis);
		
		DateFormat format2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		//得到我须要的时间    当天最后一秒
		Date resultDate=new Date(resultMis);
		System.out.println("resultDate:"+resultDate);
		System.out.println("FormatResult:"+format2.format(resultDate));
	 
	}

}
/**
 * output:
2014-06-17
Tue Jun 17 00:00:00 CST 2014
一天的毫秒-1:86400000
curMillisecond:Tue Jun 17 00:00:00 CST 2014
resultMis:1403020799999
resultDate:Tue Jun 17 23:59:59 CST 2014
FormatResult:2014-06-17 23:59:59
*/


posted on 2017-06-08 08:25  cynchanpin  阅读(6513)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3