Search in sources :

Example 86 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android-app by eoecn.

the class DateUtil method getDiffHour.

/**
	 * 获取两个时间串时间的差值,单位为小时
	 * 
	 * @param startTime
	 *            开始时间 yyyy-MM-dd HH:mm:ss
	 * @param endTime
	 *            结束时间 yyyy-MM-dd HH:mm:ss
	 * @return 两个时间的差值(秒)
	 */
public static int getDiffHour(String startTime, String endTime) {
    long diff = 0;
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
        Date startDate = ft.parse(startTime);
        Date endDate = ft.parse(endTime);
        diff = startDate.getTime() - endDate.getTime();
        diff = diff / (1000 * 60 * 60);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return new Long(diff).intValue();
}
Also used : ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 87 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android-app by eoecn.

the class DetailsDiscussActivity method Date.

private String Date(String longtime) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Long time = new Long(longtime + "000");
    String result = format.format(time);
    return result;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat)

Example 88 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android-app by eoecn.

the class DateUtil method getDateFromString.

/**
	 * 取得给定字符串描述的日期对象,描述模式采用pattern指定的格式.
	 * 
	 * @param dateStr
	 *            日期描述
	 * @param pattern
	 *            日期模式
	 * @return 给定字符串描述的日期对象。
	 */
public static Date getDateFromString(String dateStr, String pattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    Date resDate = null;
    try {
        resDate = sdf.parse(dateStr);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return resDate;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParseException(java.text.ParseException)

Example 89 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android-app by eoecn.

the class DateUtil method getCurrentDateString.

/**
	 * 根据主机的默认 TimeZone,来获得指定形式的时间字符串。
	 * @param dateFormat
	 * @return  返回日期字符串,形式和formcat一致。
	 */
public static String getCurrentDateString(String dateFormat) {
    Calendar cal = Calendar.getInstance(TimeZone.getDefault());
    SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
    sdf.setTimeZone(TimeZone.getDefault());
    return sdf.format(cal.getTime());
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 90 with SimpleDateFormat

use of java.text.SimpleDateFormat in project android-app by eoecn.

the class DateUtil method getDateByAddHour.

/**
	 * 返回指定时间加指定小时数后的日期时间。
	 * <p>
	 * 格式:yyyy-MM-dd HH:mm:ss
	 * 
	 * @return 时间.
	 */
public static String getDateByAddHour(String datetime, int minute) {
    String returnTime = null;
    Calendar cal = new GregorianCalendar();
    SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date;
    try {
        date = ft.parse(datetime);
        cal.setTime(date);
        cal.add(GregorianCalendar.MINUTE, minute);
        returnTime = getFormatDateTime(cal.getTime(), "yyyy-MM-dd HH:mm:ss");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return returnTime;
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) GregorianCalendar(java.util.GregorianCalendar) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)2847 Date (java.util.Date)1590 ParseException (java.text.ParseException)463 DateFormat (java.text.DateFormat)425 Calendar (java.util.Calendar)307 Test (org.junit.Test)305 ArrayList (java.util.ArrayList)232 File (java.io.File)230 IOException (java.io.IOException)185 GregorianCalendar (java.util.GregorianCalendar)139 HashMap (java.util.HashMap)121 Locale (java.util.Locale)70 DateField (edu.uci.ics.textdb.api.field.DateField)64 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 StringField (edu.uci.ics.textdb.api.field.StringField)63 TextField (edu.uci.ics.textdb.api.field.TextField)63 Map (java.util.Map)63 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)61