gpt4 book ai didi

java - LocalDateTime 未在程序内更新

转载 作者:行者123 更新时间:2023-12-01 19:35:29 28 4
gpt4 key购买 nike

我正在使用 LocalDateTimeDateTimeFormatter 在我的程序中使用,如下所示

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH-mm-ss");
LocalDateTime now = LocalDateTime.now();

我需要获取程序中一些屏幕截图的秒数但当我使用它们时,我只得到一个时间戳

这是我的其余代码

// SCREENSHOT
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement header = driver.findElement(By.xpath(
"(.//*[normalize-space(text()) and normalize-space(.)='Button1'])[1]/following::nav[1]"));
js.executeScript("arguments[0].setAttribute('style', 'position: static !important;')", header);
Screenshot screenshot1 = new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(ShootingStrategies.scaling(2f), 1000))
.takeScreenshot(driver);
Thread.sleep(5000);
ImageIO.write(screenshot1.getImage(), "PNG", new File(Constants.ROUTE
+ "/asd/Asd/web/" + capName + now.format(dtf) + ".png"));
Thread.sleep(1000);
// // SCREENSHOT

这是我拍摄的第一张照片。我与 now.format(dtf) 连接然后当我进行第二次捕获时

// SCREENSHOT
JavascriptExecutor js1 = (JavascriptExecutor) driver;
WebElement header1 = driver.findElement(By.xpath(
"(.//*[normalize-space(text()) and normalize-space(.)='Button2'])[1]/following::nav[1]"));
js.executeScript("arguments[0].setAttribute('style', 'position: static !important;')", header1);
Screenshot screenshot2 = new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(ShootingStrategies.scaling(2f), 1000))
.takeScreenshot(driver);
Thread.sleep(5000);
ImageIO.write(screenshot2.getImage(), "PNG", new File(Constants.ROUTE
+ "/asd/Asd/web/" + capName + now.format(dtf) + ".png"));
Thread.sleep(1000);
// // SCREENSHOT

它打印出相同的时间戳,我的程序覆盖捕获

最佳答案

LocalDateTime 是一种用于表示日期和时间(不含时区)的类型。 LocalDateTime.now() 返回表示当前日期和时间的 LocalDateTime。您现在正在做的事情是调用 LocalDateTime.now() 并期望您获得的 LocalDateTime 自行更新,而不是您应该执行 LocalDateTime.now() 每次您需要当前日期和时间时。

关于java - LocalDateTime 未在程序内更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57825403/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com