Commit 4d7ab089 authored by hanson.yao's avatar hanson.yao

convert wtPart

parent 1c3228eb
package com.yonde.common;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateTimeUtil {
public static final String FORMAT = "yyyy-MM-dd hh:mm:ss";
public static Date now() {
return new Date();
}
public static String toString(Date date, String pattern) {
return new SimpleDateFormat(pattern).format(date);
}
public static Date toDate(String date, String pattern) throws Exception {
return new SimpleDateFormat(pattern).parse(date);
}
public static Date addMonths(Date date, int count) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH, count);
return calendar.getTime();
}
public static Date addDays(Date date, int days) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, days);
return calendar.getTime();
}
public static Date addHours(Date date, int count) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, count);
return calendar.getTime();
}
public static Date addMinutes(Date date, int count) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MINUTE, count);
return calendar.getTime();
}
public static int getDayOfWeek(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int day = calendar.get(Calendar.DAY_OF_WEEK);
return day != 1 ? day - 1 : 7;
}
public static int getMonthTotalDays(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
}
public static int getDayOfMonth(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.DAY_OF_MONTH);
}
public static String timeStampToString(Timestamp timestamp) {
DateFormat sdf = new SimpleDateFormat(FORMAT);
String date = "";
try {
date = sdf.format(timestamp);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment