首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >增加日期的解决方案是什么?

增加日期的解决方案是什么?
EN

Stack Overflow用户
提问于 2019-08-05 16:34:05
回答 3查看 70关注 0票数 1

--我有这个java类,每10秒在数据库中插入同一行。如何在每次插入中增加日期?

代码语言:javascript
运行
复制
 @Component
 public class ScheduledTasks {

private static final SimpleDateFormat dateFormat = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");


private final Logger log = 
LoggerFactory.getLogger(ScheduledTasks.class);


@Autowired
StandardPlanServiceImpl standardplanDao;
@Autowired
ModalityServiceImpl modalityDao;
@Scheduled(fixedRate = 10000)
public void reportCurrentTime() throws Exception {
    log.error("The time is now {}", dateFormat.format(new 
Date()));        



BigInteger bigIntegerNbpers=new BigInteger("15");
String dDate = "2019091804000000";
String dpDateTime = "2019091807000000";
String fDate = "2019091811000000";
String fpDateTime = "2019091807300000";
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
    // date/time
    .appendPattern("yyyyMMddHHmmss")
    // milliseconds (with 2 digits)
    .appendValue(ChronoField.MILLI_OF_SECOND, 2)
    // create formatter
    .toFormatter();
 standardplanDao.save(new 
StandardPlan("red",LocalDateTime.parse(dDate, 
fmt),LocalDateTime.parse(dpDateTime, 
fmt),LocalDateTime.parse(fDate, 
fmt),LocalDateTime.parse(fpDateTime, fmt),bigIntegerNbpers,"groupe 
Test","Bloc 2"));
    log.error("The Saved Line : Début datetime: " + 
LocalDateTime.parse(dDate, fmt)+ " Fin date time :" + 
LocalDateTime.parse(fDate, fmt) + " Début pause date time : " + 
LocalDateTime.parse(dpDateTime, fmt) + " Fin pause date time : " + 
LocalDateTime.parse(fpDateTime, fmt));

 List<StandardPlan> list = standardplanDao.getAllStandardPlan();

 log.error("##########################
  ########Test##################################");
 }

 }

这里是我的日志的结果.

:时间现在是2019-08-05 17:54:36+0200 :保存行:dé但日期时间: 2019-09-18T04:00 Fin date time :2019-09-18T11:00 Dé,但暂停日期: 2019-09-18T07:00 Fin暂停>日期: 2019-09-18T07:30

############################Test : The time is now 2019-08-05 17:54:46+0200 : The Saved Line : Début datetime: 2019-09-18T04:00 Fin date time :2019-09-18T11:00 Début pause date time : 2019-09-18T07:00 Fin pause > date time : 2019-09-18T07:30

############################Test

EN

Stack Overflow用户

发布于 2019-08-05 16:58:24

您可以这样做,创建一个实例变量计数器,并在日期中添加10*counter秒。在函数的末尾增加计数器。

代码语言:javascript
运行
复制
private int counter = 0;
...
LocalDateTime.parse(fpDateTime, fmt).plusSeconds(10*counter);
...
counter++;
票数 2
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57362654

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档