three months timestamp

1, valid for three months

package com.hengqin.life.idps;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.text.ParseException;

/**
 * @author: ZhenGuangLi
 * @date: 2019/10/16
 * @Description:
 */
public class uuidTest {
    public static void main(String args[]) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = sdf.parse("2019-10-23 11:20:00");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, -3);
        Date lastDate = calendar.getTime();
        System.out.println("三个月前的日期" + sdf.format(lastDate));
        calendar.setTime(lastDate);
        calendar.add(Calendar.MONTH, 3);
        Date forDate = calendar.getTime();
        System.out.println("三个月后的日期" + sdf.format(forDate));
        int pastTime = Integer.valueOf(String.valueOf(forDate.getTime() / 1000));
        System.out.println(pastTime);
    }
}

2, the date and time stamp of the conversion

    // Converts a date stamp 
    public String dateToStamp (a Date DATE) { 
        Long date.getTime IT = (); 
        return String.valueOf (IT); 
    } 
    // convert into a date stamp 
    public stampToDate String (String S) { 
        String RES ; 
        the SimpleDateFormat SimpleDateFormat the SimpleDateFormat new new = ( "the mM-dd-YYYY HH: mm: SS"); 
        Long Long lt new new = (S); 
        a Date = new new DATE a Date (lt); 
        RES = simpleDateFormat.format (DATE); 
        return RES ; 
    }

Guess you like

Origin www.cnblogs.com/Small-sunshine/p/11725123.html