本文整理了Java中org.threeten.bp.OffsetDateTime.now()
方法的一些代码示例,展示了OffsetDateTime.now()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OffsetDateTime.now()
方法的具体详情如下:
包路径:org.threeten.bp.OffsetDateTime
类名称:OffsetDateTime
方法名:now
[英]Obtains the current date-time from the system clock in the default time-zone.
This will query the Clock#systemDefaultZone() in the default time-zone to obtain the current date-time. The offset will be calculated from the time-zone in the clock.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
[中]从默认时区的系统时钟获取当前日期时间。
这将查询默认时区中的时钟#systemDefaultZone(),以获取当前日期时间。偏移量将根据时钟中的时区进行计算。
使用此方法将防止使用备用时钟进行测试,因为该时钟是硬编码的。
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains the current date-time from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date-time.
* Specifying the time-zone avoids dependence on the default time-zone.
* The offset will be calculated from the specified time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param zone the zone ID to use, not null
* @return the current date-time using the system clock, not null
*/
public static OffsetDateTime now(ZoneId zone) {
return now(Clock.system(zone));
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains the current date-time from the system clock in the default time-zone.
* <p>
* This will query the {@link Clock#systemDefaultZone() system clock} in the default
* time-zone to obtain the current date-time.
* The offset will be calculated from the time-zone in the clock.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @return the current date-time using the system clock, not null
*/
public static OffsetDateTime now() {
return now(Clock.systemDefaultZone());
}
代码示例来源:origin: ThreeTen/threetenbp
/**
* Obtains the current date-time from the system clock in the default time-zone.
* <p>
* This will query the {@link Clock#systemDefaultZone() system clock} in the default
* time-zone to obtain the current date-time.
* The offset will be calculated from the time-zone in the clock.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @return the current date-time using the system clock, not null
*/
public static OffsetDateTime now() {
return now(Clock.systemDefaultZone());
}
代码示例来源:origin: org.threeten/threetenbp
/**
* Obtains the current date-time from the system clock in the specified time-zone.
* <p>
* This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date-time.
* Specifying the time-zone avoids dependence on the default time-zone.
* The offset will be calculated from the specified time-zone.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @param zone the zone ID to use, not null
* @return the current date-time using the system clock, not null
*/
public static OffsetDateTime now(ZoneId zone) {
return now(Clock.system(zone));
}
代码示例来源:origin: guanpj/JReadHub
public static String getRelativeTimeSpanString(@NonNull OffsetDateTime offsetDateTime) {
long offset = 0;
try {
offset = Duration.between(offsetDateTime, OffsetDateTime.now()).toMillis();
} catch (Exception e) {
e.printStackTrace();
}
if (offset > YEAR) {
return (offset / YEAR) + " 年前";
} else if (offset > MONTH) {
return (offset / MONTH) + " 个月前";
} else if (offset > WEEK) {
return (offset / WEEK) + " 周前";
} else if (offset > DAY) {
return (offset / DAY) + " 天前";
} else if (offset > HOUR) {
return (offset / HOUR) + " 小时前";
} else if (offset > MINUTE) {
return (offset / MINUTE) + " 分钟前";
} else {
return "刚刚";
}
}
代码示例来源:origin: guanpj/JReadHub
@Override
public void bindData(RelevantTopicBean relevantTopicBean, int position) {
mRelevantTopicBean = relevantTopicBean;
LocalDate date = relevantTopicBean.getCreatedAt().toLocalDate();
int year = date.getYear();
int month = date.getMonthValue();
int day = date.getDayOfMonth();
if (year == OffsetDateTime.now().getYear()) {
mTxtDate.setText(mContext.getString(R.string.month__day, month, day));
} else {
SpannableString spannableTitle = SpannableString.valueOf(mContext.getString(R.string.month__day__year, month, day, year));
spannableTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_topic_detail_news_author)),
spannableTitle.toString().indexOf("\n") + 1,
spannableTitle.toString().indexOf("\n") + 5,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTxtDate.setText(spannableTitle);
}
mTxtContent.setText(relevantTopicBean.getTitle());
mDividerTop.setVisibility(getItemViewType() == VIEW_TYPE_TOP || getItemViewType() == VIEW_TYPE_ONLY_ONE ? View.INVISIBLE : View.VISIBLE);
mDividerBottom.setVisibility(getItemViewType() == VIEW_TYPE_BOTTOM || getItemViewType() == VIEW_TYPE_ONLY_ONE ? View.INVISIBLE : View.VISIBLE);
}
代码示例来源:origin: guanpj/JReadHub
@Override
protected void convert(BaseViewHolder holder, RelevantTopicBean relevantTopicBean) {
LocalDate date = relevantTopicBean.getCreatedAt().toLocalDate();
int year = date.getYear();
int month = date.getMonthValue();
int day = date.getDayOfMonth();
if (year == OffsetDateTime.now().getYear()) {
holder.setText(R.id.txt_date, mContext.getString(R.string.month__day, month, day));
} else {
SpannableString spannableTitle = SpannableString.valueOf(mContext.getString(R.string.month__day__year, month, day, year));
spannableTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_topic_detail_news_author)),
spannableTitle.toString().indexOf("\n") + 1,
spannableTitle.toString().indexOf("\n") + 5,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.setText(R.id.txt_date, spannableTitle);
}
holder.setText(R.id.txt_topic_trace_content, relevantTopicBean.getTitle());
holder.setVisible(R.id.view_top_line, holder.getItemViewType() == VIEW_TYPE_TOP || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true);
holder.setVisible(R.id.view_bottom_line, holder.getItemViewType() == VIEW_TYPE_BOTTOM || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true);
}
}
内容来源于网络,如有侵权,请联系作者删除!