timestamp 转 date 处理后再转timestamp

package com.jmu.ccjoin.service.impl;

import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Test {

    public static void main(String[] args) {

        Timestamp ts = new Timestamp(System.currentTimeMillis());
        Date date1 = new Date();
        date1 = ts;
        System.out.println("data1:" + date1);

        Date date2 = new Date();// 取时间
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date2);
        calendar.add(Calendar.MONTH, 1);// 次月
        calendar.add(Calendar.DATE, 1);// 把日期往后增加一天.整数往后推,负数往前移动
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 25);// 指定某天
        calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// 指定月最后一天

        date2 = calendar.getTime(); // 这个时间就是日期往后推一天的结果

        System.out.println("data2:" + date2);
        System.out.println("data3:" + new Timestamp(date2.getTime()));
    }
}

posted @ 2018-01-05 17:33  乌瑟尔  阅读(949)  评论(0编辑  收藏  举报