- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中java.time.ZonedDateTime.minusMonths()
方法的一些代码示例,展示了ZonedDateTime.minusMonths()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZonedDateTime.minusMonths()
方法的具体详情如下:
包路径:java.time.ZonedDateTime
类名称:ZonedDateTime
方法名:minusMonths
[英]Returns a copy of this ZonedDateTime with the specified period in months subtracted.
This operates on the local time-line, LocalDateTime#minusMonths(long) to the local date-time. This is then converted back to a ZonedDateTime, using the zone ID to obtain the offset.
When converting back to ZonedDateTime, if the local date-time is in an overlap, then the offset will be retained if possible, otherwise the earlier offset will be used. If in a gap, the local date-time will be adjusted forward by the length of the gap.
This instance is immutable and unaffected by this method call.
[中]返回此ZoneDateTime的副本,并减去指定的期间(以月为单位)。
这在本地时间线上运行,本地日期时间#减去本地日期时间的个月(长)。然后将其转换回ZoneDateTime,使用分区ID获取偏移量。
当转换回ZoneDateTime时,如果本地日期时间重叠,那么如果可能,将保留偏移量,否则将使用较早的偏移量。如果存在间隙,本地日期时间将根据间隙的长度向前调整。
此实例是不可变的,不受此方法调用的影响。
代码示例来源:origin: org.elasticsearch/elasticsearch
public ZonedDateTime minusMonths(long amount) {
return dt.minusMonths(amount);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch
public ZonedDateTime minusMonths(long amount) {
return dt.minusMonths(amount);
}
代码示例来源:origin: apache/servicemix-bundles
public ZonedDateTime minusMonths(long amount) {
return dt.minusMonths(amount);
}
代码示例来源:origin: stackoverflow.com
public static ZonedDateTime getFirstOfLastMonth( ZoneId z ) {
Instant instant = Instant.now();
return getFirstOfPreviousMonth( instant , z );
}
public static ZonedDateTime getFirstOfPreviousMonth( Instant instantArg , ZoneId zoneArg ) {
ZonedDateTime zdt = instantArg.atZone( zoneArg);
ZonedDateTime firstOfMonthZdt = zdt.with( TemporalAdjusters.firstDayOfMonth() );
ZonedDateTime firstOfMonthPriorZdt = firstOfMonthZdt.minusMonths( 1 );
return firstOfMonthPriorZdt;
}
代码示例来源:origin: yahoo/sherlock
/**
* Method to subtract month from given timestamp.
* @param timestamp timestamp in minutes
* @param n number of months to subtract
* @return timestamp with subtracted months
*/
public static Integer subtractMonth(Integer timestamp, int n) {
ZonedDateTime zonedDateTime = TimeUtils.zonedDateTimeFromMinutes(timestamp);
zonedDateTime = zonedDateTime.minusMonths(n);
return (int) TimeUtils.zonedDateTimestamp(zonedDateTime) / 60;
}
}
代码示例来源:origin: CodeStory/fluent-http
@Override
public Payload body(Context context) {
String uri = context.uri();
URL url = webJarUrlFinder.url(uri);
return new Payload(url)
.withHeader(CACHE_CONTROL, "public, max-age=31536000")
.withHeader(LAST_MODIFIED, RFC_1123_DATE_TIME.format(now().minusMonths(1L)))
.withHeader(EXPIRES, RFC_1123_DATE_TIME.format(now().plusWeeks(1L)));
}
代码示例来源:origin: UniversaBlockchain/universa
public boolean collect(Ledger ledger, Config config) {
if(!config.getStatsIntervalSmall().equals(smallInterval) || !config.getStatsIntervalBig().equals(bigInterval)) {
//intervals changed. need to reset node
init(ledger,config);
return false;
}
ZonedDateTime now = ZonedDateTime.now();
Map<ItemState, Integer> lastIntervalStats = ledger.getLedgerSize(lastStatsBuildTime);
ledgerStatsHistory.addLast(lastIntervalStats);
ledgerHistoryTimestamps.addLast(lastStatsBuildTime);
smallIntervalApproved = lastIntervalStats.getOrDefault(ItemState.APPROVED,0)+lastIntervalStats.getOrDefault(ItemState.REVOKED,0);
bigIntervalApproved += smallIntervalApproved;
uptimeApproved += smallIntervalApproved;
lastIntervalStats.keySet().forEach(is -> ledgerSize.put(is, ledgerSize.getOrDefault(is,0) + lastIntervalStats.get(is)));
while (ledgerHistoryTimestamps.getFirst().plus(bigInterval).isBefore(now)) {
ledgerHistoryTimestamps.removeFirst();
bigIntervalApproved -= ledgerStatsHistory.removeFirst().get(ItemState.APPROVED) + lastIntervalStats.getOrDefault(ItemState.REVOKED,0);
}
lastStatsBuildTime = now;
Map<Integer, Integer> payments = ledger.getPayments(now.truncatedTo(ChronoUnit.DAYS).minusDays(now.getDayOfMonth()-1).minusMonths(1));
payments.keySet().forEach( day -> {
});
return true;
}
代码示例来源:origin: com.cronutils/cron-utils
private ZonedDateTime toEndOfPreviousMonth(final ZonedDateTime datetime) {
final ZonedDateTime previousMonth = datetime.minusMonths(1).with(lastDayOfMonth());
final int highestHour = hours.getValues().get(hours.getValues().size() - 1);
final int highestMinute = minutes.getValues().get(minutes.getValues().size() - 1);
final int highestSecond = seconds.getValues().get(seconds.getValues().size() - 1);
return ZonedDateTime
.of(previousMonth.getYear(), previousMonth.getMonth().getValue(), previousMonth.getDayOfMonth(), highestHour, highestMinute, highestSecond, 0,
previousMonth.getZone());
}
代码示例来源:origin: com.cronutils/cron-utils
private ExecutionTimeResult getPreviousPotentialYear(final ZonedDateTime date, final TimeNode days, final int highestMonth, int highestDay,
final int highestHour, final int highestMinute, final int highestSecond) throws NoSuchValueException {
NearestValue nearestValue;
ZonedDateTime newDate;
final int previousYear = yearsValueGenerator.generatePreviousValue(date.getYear());
if (highestDay > 28) {
final int highestDayOfMonth = LocalDate.of(previousYear, highestMonth, 1).lengthOfMonth();
if (highestDay > highestDayOfMonth) {
nearestValue = days.getPreviousValue(highestDay, 1);
if (nearestValue.getShifts() > 0) {
newDate = ZonedDateTime.of(
LocalDate.of(previousYear, highestMonth, 1),
MAX_SECONDS,
date.getZone()
).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth());
return new ExecutionTimeResult(newDate, false);
} else {
highestDay = nearestValue.getValue();
}
}
}
return new ExecutionTimeResult(ZonedDateTime.of(
LocalDate.of(previousYear, highestMonth, highestDay),
LocalTime.of(highestHour, highestMinute, highestSecond),
date.getZone()),
false);
}
代码示例来源:origin: yahoo/sherlock
/**
* Decrement a zoned date time by a certain
* amount of this granularity.
*
* @param date zoned date time to decrease
* @param amount the number of times to decrease
* @return copy of the zoned date time
*/
public ZonedDateTime decrement(ZonedDateTime date, int amount) {
switch (this) {
case MINUTE:
return date.minusMinutes(amount);
case HOUR:
return date.minusHours(amount);
case DAY:
return date.minusDays(amount);
case WEEK:
return date.minusWeeks(amount);
case MONTH:
return date.minusMonths(amount);
default:
return date.minusHours(amount);
}
}
代码示例来源:origin: yahoo/sherlock
/**
* Subtract granularity intervals of this type
* from a given date time.
*
* @param now the time to subtract intervals from
* @param intervals the number of intervals to subtract
* @param granularityRange range of granularity to aggregate on
* @return a copied ZonedDateTime with the intervals subtracted
*/
public ZonedDateTime subtractIntervals(ZonedDateTime now, int intervals, int granularityRange) {
int n = intervals - (intervals % granularityRange);
switch (this) {
case MINUTE:
return now.minusMinutes(n);
case HOUR:
return now.minusHours(n);
case DAY:
return now.minusDays(n);
case WEEK:
return now.minusWeeks(n);
case MONTH:
return now.minusMonths(n);
default:
return now.minusHours(n);
}
}
代码示例来源:origin: com.cronutils/cron-utils
private ExecutionTimeResult getPreviousPotentialDayOfMonth(final ZonedDateTime date, final TimeNode days, final int highestHour, final int highestMinute,
final int highestSecond) {
NearestValue nearestValue = days.getPreviousValue(date.getDayOfMonth(), 0);
if (nearestValue.getShifts() > 0) {
ZonedDateTime newDate = ZonedDateTime.of(
LocalDate.of(date.getYear(), date.getMonthValue(), 1),
MAX_SECONDS,
date.getZone()
).minusMonths(nearestValue.getShifts()).with(lastDayOfMonth());
return new ExecutionTimeResult(newDate, false);
}
return new ExecutionTimeResult(date.withDayOfMonth(nearestValue.getValue())
.with(LocalTime.of(highestHour, highestMinute, highestSecond)).truncatedTo(SECONDS), false);
}
代码示例来源:origin: org.hibernate.beanvalidation.tck/beanvalidation-tck-tests
);
ZonedDateTime past = reference.minusMonths( 1 ).minusHours( 1 );
dummy = new PastRelativePartialDummyEntity( past );
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
@Override
public ZonedDateTime dateAddDuration(ZonedDateTime date, Duration duration) {
if (date == null || duration == null) {
return null;
}
try {
int years = duration.getYears();
int months = duration.getMonths();
int days = duration.getDays();
if (duration.getSign() == -1) {
return date
.minusYears(years)
.minusMonths(months)
.minusDays(days);
} else {
return date
.plusYears(years)
.plusMonths(months)
.plusDays(days);
}
} catch (Throwable e) {
String message = String.format("dateAdd(%s, %s)", date, duration);
logError(message, e);
return null;
}
}
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
@Override
public ZonedDateTime dateSubtractDuration(ZonedDateTime date, Duration duration) {
if (date == null || duration == null) {
return null;
}
try {
int years = duration.getYears();
int months = duration.getMonths();
int days = duration.getDays();
if (duration.getSign() == -1) {
return date
.plusYears(years)
.plusMonths(months)
.plusDays(days);
} else {
return date
.minusYears(years)
.minusMonths(months)
.minusDays(days);
}
} catch (Throwable e) {
String message = String.format("dateSubtract(%s, %s)", date, duration);
logError(message, e);
return null;
}
}
代码示例来源:origin: UniversaBlockchain/universa
@Test
public void test123() throws Exception {
ZonedDateTime now = ZonedDateTime.now();
DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
builder.appendValue(ChronoField.DAY_OF_MONTH,2);
builder.appendLiteral("/");
builder.appendValue(ChronoField.MONTH_OF_YEAR,2);
builder.appendLiteral("/");
builder.appendValue(ChronoField.YEAR,4);
System.out.println(now.format(builder.toFormatter()));
System.out.println(now.truncatedTo(ChronoUnit.DAYS).format(builder.toFormatter()));
System.out.println(now.truncatedTo(ChronoUnit.DAYS).minusDays(now.getDayOfMonth()-1).format(builder.toFormatter()));
System.out.println(now.truncatedTo(ChronoUnit.DAYS).minusDays(now.getDayOfMonth()-1).minusMonths(1).format(builder.toFormatter()));
}
代码示例来源:origin: goldmansachs/jdmn
@Override
public ZonedDateTime dateAddDuration(ZonedDateTime date, Duration duration) {
if (date == null || duration == null) {
return null;
}
try {
int years = duration.getYears();
int months = duration.getMonths();
int days = duration.getDays();
if (duration.getSign() == -1) {
return date
.minusYears(years)
.minusMonths(months)
.minusDays(days);
} else {
return date
.plusYears(years)
.plusMonths(months)
.plusDays(days);
}
} catch (Throwable e) {
String message = String.format("dateAdd(%s, %s)", date, duration);
logError(message, e);
return null;
}
}
代码示例来源:origin: goldmansachs/jdmn
@Override
public ZonedDateTime dateSubtractDuration(ZonedDateTime date, Duration duration) {
if (date == null || duration == null) {
return null;
}
try {
int years = duration.getYears();
int months = duration.getMonths();
int days = duration.getDays();
if (duration.getSign() == -1) {
return date
.plusYears(years)
.plusMonths(months)
.plusDays(days);
} else {
return date
.minusYears(years)
.minusMonths(months)
.minusDays(days);
}
} catch (Throwable e) {
String message = String.format("dateSubtract(%s, %s)", date, duration);
logError(message, e);
return null;
}
}
代码示例来源:origin: UniversaBlockchain/universa
@Test
public void paymentSaveTest() throws Exception {
try (PooledDb db = (PooledDb) ledger.getDb()) {
try (PreparedStatement statement = db.statement("delete from payments_summary;")
) {
statement.executeUpdate();
}
}
NodeStats stats = new NodeStats();
Config config = new Config();
stats.init(ledger,config);
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime dateTime = now.minusDays(now.getDayOfMonth()-1).minusMonths(1);
while (dateTime.isBefore(ZonedDateTime.now().plusSeconds(1))) {
ledger.savePayment(100,dateTime);
ledger.savePayment(100,dateTime);
dateTime = dateTime.plusDays(1);
}
stats.collect(ledger,config);
//assertEquals(stats.todayPaidAmount,200);
//assertEquals(stats.yesterdayPaidAmount,200);
//assertEquals(stats.thisMonthPaidAmount,200*now.getDayOfMonth());
//assertEquals(stats.lastMonthPaidAmount,200*now.minusMonths(1).getMonth().length(now.getYear() % 4 == 0));
}
代码示例来源:origin: com.goldmansachs.jdmn/jdmn-core
return dateTime
.minusYears(years)
.minusMonths(months)
.minusDays(days)
.minusHours(hours)
在尝试 time 的 python 执行时,我发现在一条语句中两次调用 time.time() 时出现奇怪的行为。在语句执行期间获取time.time() 有一个非常小的处理延迟。 例如time.ti
我要疯了。对于我的生活,我无法弄清楚为什么以下代码会导致 Unity 在我按下播放键后立即卡住。这是一个空的项目,脚本附加到一个空的游戏对象。在控制台中,什么也没有出现,甚至没有出现初始的 Debug
我要疯了。对于我的生活,我无法弄清楚为什么以下代码会导致 Unity 在我按下播放键后立即卡住。这是一个空的项目,脚本附加到一个空的游戏对象。在控制台中,什么也没有出现,甚至没有出现初始的 Debug
我不明白为什么下面的结果是一样的。我预计第一个结果是指针地址。 func print(t *time.Time) { fmt.Println(t) // 2009-11-10 23:00:00
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32 Type "help
当我有一个time.Time时: // January, 29th t, _ := time.Parse("2006-01-02", "2016-01-29") 如何获得代表 1 月 31 日的 ti
首先,我意识到不推荐使用 time with time zone。我要使用它是因为我将多个 time with time zone 值与我当前的系统时间进行比较,而不管是哪一天。 IE。用户说每天 0
长期以来,在 Rust 中精确测量时间的标准方法是 time crate 及其 time::precise_time_ns功能。但是,time crate 现在已被弃用,std 库有 std::tim
我正在我学校的一个科学集群上运行我的有限差分程序。该程序使用 openmpi 来并行化代码。 当程序连续运行时,我得到: real 78m40.592s user 78m34.920s s
尽管它们已被弃用并且有比 time 更好的模块(即 timeit),但我想知道这两个函数 time 之间的区别.clock() 和 time.time()。 从后者 (time.time()) 开始,
这个问题在这里已经有了答案: Python's time.clock() vs. time.time() accuracy? (16 个答案) 关闭 6 年前。 我认为两者都衡量时间量?但是他们返回
我正在尝试测试 http 请求处理代码块在我的 Flask Controller 中需要多长时间,这是我使用的示例代码: cancelled = [] t0 = time.time() t1 = ti
运行 python 的计算机时钟(Windows 或 Linux)时会发生什么自动更改并调用 time.time()? 我读到,当时钟手动更改为过去的某个值时,time.time() 的值会变小。 最
我有一个结构可能无法在其字段之一上设置 time.Time 值。测试无效性时,我不能使用 nil 或 0。time.Unix(0,0) 也不相同。我想到了这个: var emptyTime time.
我有一个打算用数据库记录填充的结构,其中一个日期时间列可以为空: type Reminder struct { Id int CreatedAt time.Time
问题陈述:通过匹配其百分比随机执行各种命令。比如执行 CommandA 50% 的时间和 commandB 25% 的时间和 commandC 15% 的时间等等,总百分比应该是 100%。 我的问题
我正在使用 laravel 6。我在同一个应用程序中有类似的 Controller 和类似的 View ,它工作正常。对比之后还是找不到错误。 Facade\Ignition\Exceptions\V
我需要用 ("%m/%d/%Y %H:%M:%S") 格式表示时间,我得到的浮点值是 time.time(). 我已经有了一个 time.time() 形式的值。例如,我已经有一个值,我每 0.3 秒
我正在使用以下方法获取 utc 日期时间: import datetime import time from pytz import timezone now_utc = datetime.datet
我在 Ubuntu 上使用 time.clock 和 time.time 为一段 python 代码计时: clock elapsed time: 8.770 s time elapsed time
我是一名优秀的程序员,十分优秀!