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();
}
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;
}
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;
}
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());
}
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;
}
Aggregations