package com.XX.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* Created by apple on 2017/10/1.
*/
public class DateUtil {
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static String format(Date date) {
return sdf.format(date);
}
public static Date getTimeByMinusHour(Date date, int n) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MINUTE, -1*n);
return cal.getTime();
}
public static String dateToStr(java.util.Date dateDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyMMdd");
String dateString = formatter.format(dateDate);
return dateString;
}
public static void main(String[] args) {
Date date = new Date();
String dateString = dateToStr(date);
String talbe = "DD"+dateString;
System.out.print(talbe);
}
}