本文整理汇总了Java中java.time.LocalDateTime.plusDays方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.plusDays方法的具体用法?Java LocalDateTime.plusDays怎么用?Java LocalDateTime.plusDays使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.plusDays方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTimestamp
import java.time.LocalDateTime; //导入方法依赖的package包/类
public Timestamp getTimestamp(String daysS, String hoursS, String minutesS){
daysS = daysS==null || daysS.equals("") ? "0" : daysS;
hoursS = hoursS==null || hoursS.equals("") ? "0" : hoursS;
minutesS = minutesS==null || minutesS.equals("") ? "0" : minutesS;
Integer days = Integer.parseInt(daysS);
Integer hours = Integer.parseInt(hoursS);
Integer minutes = Integer.parseInt(minutesS);
if(days==0 && hours==0 && minutes==0){
days = 10000;
hours = 11;
minutes = 59;
}
days = days > 10000 ? 10000 : days;
hours = hours%24;
minutes = minutes%60;
LocalDateTime localDateTime = LocalDateTime.now();
localDateTime = localDateTime.plusDays(days);
localDateTime = localDateTime.plusHours(hours);
localDateTime = localDateTime.plusMinutes(minutes);
return Timestamp.valueOf(localDateTime);
}
示例2: schedule
import java.time.LocalDateTime; //导入方法依赖的package包/类
private void schedule() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime next = renewalCheckTime.atDate(now.toLocalDate());
if (next.isBefore(now)) {
next = next.plusDays(1);
}
if (activeTimerId != null) {
vertx.cancelTimer(activeTimerId);
activeTimerId = null;
}
activeTimerId = vertx.setTimer(now.until(next, MILLIS), timerId -> {
logger.info("Renewal check starting");
activeTimerId = null;
Future<Void> checked;
try {
checked = check();
} catch (IllegalStateException e) {
// someone else already updating, skip
checked = failedFuture(e);
}
checked.setHandler(ar -> {
if (ar.succeeded()) {
logger.info("Renewal check completed successfully");
} else {
logger.warn("Renewal check failed", ar.cause());
}
});
});
logger.info("Scheduled next renewal check at " + next);
}
示例3: testGernerate
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Ignore
@Test
public void testGernerate() throws IOException {
LocalDateTime localDateTime1 = LocalDateTime.of(2013, 12, 31, 23, 59, 59);
LocalDateTime localDateTime2 = LocalDateTime.of(2017, 1, 1, 0, 0, 0);
LocalDateTime date1 = LocalDateTime.of(2003, 12, 31, 23, 59, 59);
LocalDateTime date2 = LocalDateTime.of(2007, 1, 1, 0, 0, 0);
List<String> lines = new ArrayList<>();
lines.add("<?xml version='1.0' encoding='UTF-8'?>");
lines.add("<dataset>");
for (Long id = 1L; id <= 1000; id++) {
String line = "<TEST_DATES_ENTITY ID='" + id + "'";
line += " LOCAL_DATE_TIME1='" + localDateTime1.format(DATE_PATTERN) + "'";
line += " LOCAL_DATE_TIME2='" + localDateTime2.format(DATE_PATTERN) + "'";
line += " DATE1='" + date1.format(DATE_PATTERN) + "'";
line += " DATE2='" + date2.format(DATE_PATTERN) + "' />";
lines.add(line);
localDateTime1 = localDateTime1.plusDays(1L);
localDateTime2 = localDateTime2.minusHours(6L);
date1 = date1.plusDays(1L);
date2 = date2.minusHours(6L);
}
lines.add("</dataset>");
Path file = Paths.get("src/test/resources/date-dataset.xml");
Files.write(file, lines, Charset.forName("UTF-8"));
}
示例4: getVehiclesMotTestsByDateRange_SetsTimestampsCorrectly
import java.time.LocalDateTime; //导入方法依赖的package包/类
public void getVehiclesMotTestsByDateRange_SetsTimestampsCorrectly() throws SQLException {
final LocalDateTime startDateTime = LocalDateTime.of(2000, 1, 1, 7, 0);
final LocalDateTime endDateTime = startDateTime.plusDays(1);
final Date startDate = Date.from(startDateTime.toInstant(ZoneOffset.UTC));
final Date endDate = Date.from(endDateTime.toInstant(ZoneOffset.UTC));
final Timestamp startTimestamp = new Timestamp(startDate.getTime());
final Timestamp endTimestamp = new Timestamp(endDate.getTime());
when(connectionMock.prepareStatement(TradeReadSql.QUERY_GET_VEHICLES_MOT_TESTS_BY_DATE_RANGE))
.thenReturn(preparedStatementMock);
when(preparedStatementMock.executeQuery()).thenReturn(resultSetMock);
tradeReadDao.getVehiclesMotTestsByDateRange(startDate, endDate);
verify(preparedStatementMock).setObject(1, startTimestamp);
verify(preparedStatementMock).setObject(2, endTimestamp);
verify(preparedStatementMock).setObject(3, startTimestamp);
verify(preparedStatementMock).setObject(4, endTimestamp);
verify(preparedStatementMock).setObject(5, endTimestamp);
verify(preparedStatementMock).setObject(6, startTimestamp);
verify(preparedStatementMock).setObject(7, endTimestamp);
verify(preparedStatementMock).setObject(8, startTimestamp);
verify(preparedStatementMock).setObject(9, endTimestamp);
verify(preparedStatementMock).setObject(10, endTimestamp);
}
示例5: getEndCookieDate
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static Date getEndCookieDate(int days) {
Date date = new Date();
LocalDateTime localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
localDate = localDate.plusDays(days);
Date cookieEndDate = Date.from(localDate.atZone(ZoneId.systemDefault()).toInstant());
return cookieEndDate;
}
示例6: saveCompteMinima
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Enregistre un compte à minima
*
* @param cptMin
* @return le compte enregistré
*/
private CompteMinima saveCompteMinima(CompteMinima cptMin) {
// Generateur de mot de passe
PasswordHashService passwordHashUtils = PasswordHashService.getCurrentImplementation();
Campagne campagne = campagneController.getCampagneActive();
if (campagne == null) {
Notification.show(
applicationContext.getMessage("compteMinima.camp.error", null, UI.getCurrent().getLocale()),
Type.ERROR_MESSAGE);
return null;
}
cptMin.setCampagne(campagne);
String prefix = parametreController.getPrefixeNumDossCpt();
Integer sizeNumDossier = ConstanteUtils.GEN_SIZE;
if (prefix != null) {
sizeNumDossier = sizeNumDossier - prefix.length();
}
String numDossierGenere = passwordHashUtils.generateRandomPassword(sizeNumDossier, ConstanteUtils.GEN_NUM_DOSS);
while (isNumDossierExist(numDossierGenere)) {
numDossierGenere = passwordHashUtils.generateRandomPassword(sizeNumDossier, ConstanteUtils.GEN_NUM_DOSS);
}
if (prefix != null) {
numDossierGenere = prefix + numDossierGenere;
}
cptMin.setNumDossierOpiCptMin(numDossierGenere);
String pwd = passwordHashUtils.generateRandomPassword(ConstanteUtils.GEN_SIZE, ConstanteUtils.GEN_PWD);
try {
cptMin.setPwdCptMin(passwordHashUtils.createHash(pwd));
cptMin.setTypGenCptMin(passwordHashUtils.getType());
} catch (CustomException e) {
Notification.show(
applicationContext.getMessage("compteMinima.pwd.error", null, UI.getCurrent().getLocale()),
Type.ERROR_MESSAGE);
return null;
}
/* La date avant destruction */
LocalDateTime datValid = LocalDateTime.now();
Integer nbJourToKeep = parametreController.getNbJourKeepCptMin();
datValid = datValid.plusDays(nbJourToKeep);
datValid = LocalDateTime.of(datValid.getYear(), datValid.getMonth(), datValid.getDayOfMonth(), 23, 0, 0);
cptMin.setDatFinValidCptMin(datValid);
try {
cptMin = saveBaseCompteMinima(cptMin, campagne);
} catch (Exception ex) {
logger.error(
applicationContext.getMessage("compteMinima.numdossier.error", null, UI.getCurrent().getLocale())
+ " numDossier=" + numDossierGenere,
ex);
Notification.show(
applicationContext.getMessage("compteMinima.numdossier.error", null, UI.getCurrent().getLocale()),
Type.ERROR_MESSAGE);
return null;
}
CptMinMailBean mailBean = new CptMinMailBean(cptMin.getPrenomCptMin(), cptMin.getNomCptMin(),
cptMin.getNumDossierOpiCptMin(), pwd, getLienValidation(numDossierGenere),
campagneController.getLibelleCampagne(cptMin.getCampagne(), getCodLangueCptMin(cptMin)),
formatterDate.format(cptMin.getDatFinValidCptMin()));
mailController.sendMailByCod(cptMin.getMailPersoCptMin(), NomenclatureUtils.MAIL_CPT_MIN, mailBean, null,
getCodLangueCptMin(cptMin));
Notification.show(
applicationContext.getMessage("compteMinima.create.success", null, UI.getCurrent().getLocale()),
Type.WARNING_MESSAGE);
return cptMin;
}
示例7: createCompteMinima
import java.time.LocalDateTime; //导入方法依赖的package包/类
public CompteMinima createCompteMinima() {
logger.debug("Creation du compte");
// Generateur de mot de passe
PasswordHashService passwordHashUtils = PasswordHashService.getCurrentImplementation();
Campagne campagne = campagneController.getCampagneActive();
CompteMinima cptMin = new CompteMinima();
cptMin.setCampagne(campagne);
cptMin.setMailPersoCptMin("[email protected]");
cptMin.setNomCptMin("TEST-LB-NOM");
cptMin.setPrenomCptMin("TEST-LB-PRENOM");
cptMin.setTemValidCptMin(true);
cptMin.setTemValidMailCptMin(true);
cptMin.setTemFcCptMin(false);
LocalDateTime datValid = LocalDateTime.now();
Integer nbJourToKeep = parametreController.getNbJourKeepCptMin();
datValid = datValid.plusDays(nbJourToKeep);
datValid = LocalDateTime.of(datValid.getYear(), datValid.getMonth(), datValid.getDayOfMonth(), 23, 0, 0);
cptMin.setDatFinValidCptMin(datValid);
String prefix = parametreController.getPrefixeNumDossCpt();
Integer sizeNumDossier = ConstanteUtils.GEN_SIZE;
if (prefix != null) {
sizeNumDossier = sizeNumDossier - prefix.length();
}
String numDossierGenere = passwordHashUtils.generateRandomPassword(sizeNumDossier, ConstanteUtils.GEN_NUM_DOSS);
while (isNumDossierExist(numDossierGenere)) {
numDossierGenere = passwordHashUtils.generateRandomPassword(sizeNumDossier, ConstanteUtils.GEN_NUM_DOSS);
}
if (prefix != null) {
numDossierGenere = prefix + numDossierGenere;
}
cptMin.setNumDossierOpiCptMin(numDossierGenere);
String pwd = passwordHashUtils.generateRandomPassword(ConstanteUtils.GEN_SIZE, ConstanteUtils.GEN_PWD);
pwd = "123";
try {
cptMin.setPwdCptMin(passwordHashUtils.createHash(pwd));
cptMin.setTypGenCptMin(passwordHashUtils.getType());
} catch (CustomException e) {
return null;
}
String codLangue = "fr";
try {
logger.debug("Creation compte NoDossier = " + cptMin.getNumDossierOpiCptMin());
/* Enregistrement de l'historique */
histoNumDossierRepository
.saveAndFlush(new HistoNumDossier(cptMin.getNumDossierOpiCptMin(), campagne.getCodCamp()));
/* Enregistrement du compte */
cptMin = compteMinimaRepository.saveAndFlush(cptMin);
CptMinMailBean mailBean = new CptMinMailBean(cptMin.getPrenomCptMin(), cptMin.getNomCptMin(),
cptMin.getNumDossierOpiCptMin(), pwd, "http://lien-validation-" + numDossierGenere,
campagneController.getLibelleCampagne(cptMin.getCampagne(), codLangue),
formatterDate.format(cptMin.getDatFinValidCptMin()));
mailController.sendMailByCod(cptMin.getMailPersoCptMin(), NomenclatureUtils.MAIL_CPT_MIN, mailBean, null,
codLangue);
return cptMin;
} catch (Exception ex) {
logger.error(
applicationContext.getMessage("compteMinima.numdossier.error", null, UI.getCurrent().getLocale())
+ " numDossier=" + numDossierGenere,
ex);
return null;
}
}
示例8: generateRoster
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Transactional
public Roster generateRoster(int spotListSize, int timeSlotListSize, boolean continuousPlanning) {
int employeeListSize = spotListSize * 7 / 2;
int skillListSize = (spotListSize + 4) / 5;
Integer tenantId = createTenant(spotListSize, employeeListSize);
List<Skill> skillList = createSkillList(tenantId, skillListSize);
List<Spot> spotList = createSpotList(tenantId, spotListSize, skillList);
List<Employee> employeeList = createEmployeeList(tenantId, employeeListSize, skillList);
shiftRestService.createTemplate(tenantId, generateShiftTemplate(tenantId, spotList, employeeList));
LocalDateTime previousEndDateTime = LocalDateTime.of(2017, 2, 1, 6, 0);
for (int i = 0; i < timeSlotListSize; i += 7) {
try {
shiftRestService.addShiftsFromTemplate(tenantId, previousEndDateTime.toString(), previousEndDateTime
.plusDays(7).toString());
previousEndDateTime = previousEndDateTime.plusWeeks(1);
} catch (Exception e) {
throw new IllegalStateException(e);
}
previousEndDateTime = previousEndDateTime.plusDays(7);
}
List<TimeSlot> timeSlotList = entityManager.createNamedQuery("TimeSlot.findAll", TimeSlot.class)
.setParameter("tenantId", tenantId)
.getResultList();
List<Shift> shiftList = entityManager.createNamedQuery("Shift.findAll", Shift.class)
.setParameter("tenantId", tenantId)
.getResultList();
List<EmployeeAvailability> employeeAvailabilityList = entityManager
.createNamedQuery("EmployeeAvailability.findAll", EmployeeAvailability.class)
.setParameter("tenantId", tenantId)
.getResultList();
Tenant tenant = entityManager.find(Tenant.class, tenantId);
return new Roster((long) tenantId, tenantId,
skillList, spotList, employeeList, timeSlotList, employeeAvailabilityList,
tenant.getConfiguration(), shiftList);
}
示例9: testClacPlus
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 时间运算,计算完成后会返回新的对象,并不会改变原来的时间
*/
@Test
public void testClacPlus() {
LocalDateTime ldt = LocalDateTime.now();
System.out.println(ldt);
// 加: 天
LocalDateTime day = ldt.plusDays(1);
System.out.println("day: " + day);
// 加: 小时
LocalDateTime hours = ldt.plusHours(1);
System.out.println("hours: " + hours);
// 加: 分钟
LocalDateTime minutes = ldt.plusMinutes(1);
System.out.println("minutes: " + minutes);
// 加: 月
LocalDateTime months = ldt.plusMonths(1);
System.out.println("months: " + months);
// 加: 纳秒
LocalDateTime nanos = ldt.plusNanos(1);
System.out.println("nanos: " + nanos);
// 加: 秒
LocalDateTime seconds = ldt.plusSeconds(1);
System.out.println("seconds: " + seconds);
// 加: 周
LocalDateTime weeks = ldt.plusWeeks(1);
System.out.println("weeks: " + weeks);
// 加: 年
LocalDateTime years = ldt.plusYears(1);
System.out.println("years: " + years);
System.out.println(ldt);
}
示例10: plusDay
import java.time.LocalDateTime; //导入方法依赖的package包/类
public LocalDateTime plusDay(LocalDateTime input) {
return input.plusDays(1);
}
示例11: addDay
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* 计算 day 天后的时间
*
* @param date 长日期
* @param day 增加的天数
* @return 增加后的日期
*/
public static LocalDateTime addDay(LocalDateTime date, int day) {
return date.plusDays(day);
}