本文整理汇总了Java中org.threeten.bp.LocalDateTime.format方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.format方法的具体用法?Java LocalDateTime.format怎么用?Java LocalDateTime.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.threeten.bp.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.format方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LocalDateTime_to_String
import org.threeten.bp.LocalDateTime; //导入方法依赖的package包/类
public static String LocalDateTime_to_String(LocalDateTime date)
{
return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
示例2: formatTime
import org.threeten.bp.LocalDateTime; //导入方法依赖的package包/类
private String formatTime(LocalDateTime time) {
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
return time.format(formatter);
}
示例3: toText
import org.threeten.bp.LocalDateTime; //导入方法依赖的package包/类
@ToJson
public String toText(LocalDateTime dateTime) {
return dateTime.format(formatter);
}
示例4: toDurationFriendly
import org.threeten.bp.LocalDateTime; //导入方法依赖的package包/类
public static String toDurationFriendly(Context context, Date date) {
final Instant instant = DateTimeUtils.toInstant(date);
LocalDateTime target = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
LocalDateTime now = LocalDateTime.now();
Duration duration;
if (target.isAfter(now.minusMinutes(1))) {
return context.getResources().getString(R.string.just_now);
}
if (target.isAfter(now.minusHours(1))) {
duration = Duration.between(now, target);
return context.getResources().getString(R.string.minutes_ago, Math.abs(duration.toMinutes()));
}
if (target.isAfter(now.minusDays(1))) {
duration = Duration.between(now, target);
return context.getResources().getString(R.string.hours_ago, Math.abs(duration.toHours()));
}
if (target.isAfter(now.minusWeeks(1))) {
duration = Duration.between(target, now);
return context.getResources().getString(R.string.days_ago, Math.abs(duration.toDays()));
}
// http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
return target.format(DateTimeFormatter.ISO_LOCAL_DATE);
//if (now.isEqual(target)) {
// duration = Duration.between(now, target);
// return target.format(DateTimeFormatter.ISO_TIME);
//}
// 本周
//TemporalField chinaField = WeekFields.of(Locale.CHINA).dayOfWeek();
//LocalDate start = now.with(chinaField, 1);
//LocalDate end = now.with(chinaField, 7);
//if (target.isAfter(start) && target.isBefore(end)) {
// return target.format()
//}
// 一周内
//LocalDate from = now.minusDays(7);
//if (target.isAfter(from)) {
//
// return duration.toDays() + " 天前";
//}
}