java 日期操作

package com.jy.util;

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

public class DateUtil {

private Calendar calendar = new GregorianCalendar();

public String getDate() {
StringBuffer sbf = new StringBuffer();
sbf.append(calendar.get(Calendar.YEAR)).append("-");
sbf.append(this.addZero((calendar.get(Calendar.MONTH) + 1), 2)).append(
"-");
sbf.append(this.addZero(calendar.get((Calendar.DAY_OF_MONTH)), 2));
return sbf.toString();
}

public String addZero(int temp, int len) {
StringBuffer sbf = new StringBuffer();
sbf.append(temp);
while (sbf.length() < len) {
sbf.insert(0, 0);
}
return sbf.toString();
}

public String getMaxTime(String date) {
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, Integer.parseInt(date));
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String mDateTime = formatter.format(c.getTime()) + " 23:59:59";
return mDateTime;
}

public static String DateFormat(long date) {
String result = "";
Date d = new Date(date);
/* SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); */
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
result = sdf.format(d);
return result;
}

/**
* @param date
* @param min
* @return
* @throws Exception
*/
public static String compareTime(String date, String min) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dd = "2010-11-30 14:46:33";
String de = "2010-11-30 14:55:33";
Calendar c = new GregorianCalendar();
c.setTime(sdf.parse(dd));
long s = System.currentTimeMillis();
c.add(Calendar.MINUTE, 10 * 600);

System.out.println(c.getTime());
long e = System.currentTimeMillis();
System.out.println(e - s);
System.out.println(c.getTime().after(sdf.parse(de)));
return null;
}

public static void main(String[] args) throws Exception {
/*
* DateUtil date = new DateUtil(); System.out.println(date.getDate());
*/
System.out.println(compareTime("", ""));
}
}

你可能感兴趣的:(java,C++,c,C#)