zoukankan      html  css  js  c++  java
  • 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
    */
    


  • 相关阅读:
    C++对象模型
    C/C++内存结构
    第一篇
    Goodbye Steve(19552011)
    DirectX学习笔记_关于Sprite.Draw2D的说明
    Goodbye World!
    js把一个数组的数据平均到几个数组里面
    Django model字段类型清单
    Golang中间件——goredis操作Redis
    Python开发一个短网址生成器
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/6960930.html
Copyright © 2011-2022 走看看