DateUtils {
String = String = String = String = String = String = String (Calendar calendarString pattern) {
SimpleDateFormat format1 = SimpleDateFormat(pattern)format1.format(calendar.getTime())}
Calendar (String dateTimeStrString patternStr) {
{
SimpleDateFormat sdf = SimpleDateFormat(patternStrLocale.)sdf.setLenient()Date d = sdf.parse(dateTimeStr)Calendar c = Calendar.()c.setLenient()c.setTimeInMillis(d.getTime())c} (Exception e) {
IllegalArgumentException(e)}
}
(Calendar fromCalendar to) {
dayMillis = * * * betweenDaysCalendar c1 = Calendar.()c1.set(from.get(Calendar.)from.get(Calendar.)from.get(Calendar.))c1.set(Calendar.)Calendar c2 = Calendar.()c2.set(to.get(Calendar.)to.get(Calendar.)to.get(Calendar.))c2.set(Calendar.)a = c1.getTimeInMillis()b = c2.getTimeInMillis()bt = Math.(a - b)betweenDays = ()(bt / dayMillis)betweenDays}
(String startdateString enddateString pattern) {
betweenDays = (startdate == || enddate == ) {
betweenDays}
Calendar d1 = (startdatepattern)Calendar d2 = (enddatepattern)(d1d2)}
(String time) {
SimpleDateFormat sf = SimpleDateFormat()Date date = Date(){
date = sf.parse(time)} (ParseException e) {
LogUtil.(e)}
date.getTime()}
String (time) {
SimpleDateFormat sf = SimpleDateFormat()Date d = Date(time)sf.format(d)}
String (elapsedSeconds) {
hours = minutes = seconds(elapsedSeconds >= ) {
hours = elapsedSeconds / elapsedSeconds -= hours * }
(elapsedSeconds >= ) {
minutes = elapsedSeconds / elapsedSeconds -= minutes * }
seconds = elapsedSecondsStringBuilder sb = StringBuilder()Formatter f = {
f = Formatter(sbLocale.())(hours > ) {
f.format(hoursminutesseconds).toString()} {
f.format(minutesseconds).toString()}
} {
(f != ) {
f.close()}
}
}
String (milliseconds) {
DateFormat format = SimpleDateFormat.()format.format(Date(milliseconds))}
String (millisecondsLocale locale) {
DateFormat format = SimpleDateFormat.(DateFormat.locale)format.format(Date(milliseconds))}
(currentTimelastTime) {
currentTime - lastTime >= }
String (milliseconds) {
SimpleDateFormat sf = SimpleDateFormat()Date d = Date(milliseconds)sf.format(d)}
String (milliseconds) {
SimpleDateFormat sf = SimpleDateFormat()Date d = Date(milliseconds)sf.format(d)}
String (Context contexttimeMillis) {
(context == )
dTime = System.() - timeMillis(dTime < )
(timeMillis)(dTime < * * )
context.getString(R.string.)(dTime < * * )
context.getString(R.string.)Calendar last = Calendar.()last.setFirstDayOfWeek(Calendar.)last.setTimeInMillis(timeMillis)Calendar temp = Calendar.()temp.setFirstDayOfWeek(Calendar.)temp.set(Calendar.)temp.set(Calendar.)temp.set(Calendar.)temp.set(Calendar.)(!last.before(temp))
(timeMillis)temp.add(Calendar.-)(!last.before(temp))
context.getString(R.string.)temp.add(Calendar.-)(!last.before(temp)) {
week = last.get(Calendar.) - context.getResources().getStringArray(R.array.)[week % ]}
(timeMillis)}
String (timeMillisString pattern) {
(TextUtils.(pattern))
pattern = SimpleDateFormat formatter = SimpleDateFormat(pattern)Date = Date(timeMillis)formatter.format()}
}
转载于:https://my.oschina.net/haofjguojd/blog/618813