java.time.LocalDateTime.now()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(282)

本文整理了Java中java.time.LocalDateTime.now()方法的一些代码示例,展示了LocalDateTime.now()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.now()方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:now

LocalDateTime.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.

Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
[中]从默认时区中的系统时钟获取当前日期时间。
这将查询默认时区中的时钟#systemDefaultZone(),以获取当前日期时间。
使用此方法将防止使用备用时钟进行测试,因为该时钟是硬编码的。

代码示例

代码示例来源:origin: alibaba/Sentinel

@Override
public String sayHello(String name) {
  return String.format("Hello, %s at %s", name, LocalDateTime.now());
}

代码示例来源:origin: alibaba/Sentinel

@Override
public String sayHello(String name) {
  return String.format("Hello, %s at %s", name, LocalDateTime.now());
}

代码示例来源:origin: neo4j/neo4j

private String getDefaultFilename() throws UnknownHostException
{
  String hostName = InetAddress.getLocalHost().getHostName();
  String safeFilename = hostName.replaceAll( "[^a-zA-Z0-9._]+", "_" );
  return safeFilename + "-" + LocalDateTime.now().format( filenameDateTimeFormatter ) + ".zip";
}

代码示例来源:origin: alibaba/Sentinel

@Override
  public String doAnother() {
    return LocalDateTime.now().toString();
  }
}

代码示例来源:origin: alibaba/Sentinel

@Override
  public String doAnother() {
    return LocalDateTime.now().toString();
  }
}

代码示例来源:origin: neo4j/neo4j

public static LocalDateTimeValue now( Clock clock )
{
  return new LocalDateTimeValue( LocalDateTime.now( clock ) );
}

代码示例来源:origin: linlinjava/litemall

public void add(LitemallBrand brand) {
  brand.setAddTime(LocalDateTime.now());
  brand.setUpdateTime(LocalDateTime.now());
  brandMapper.insertSelective(brand);
}

代码示例来源:origin: linlinjava/litemall

public void add(LitemallAdmin admin) {
  admin.setAddTime(LocalDateTime.now());
  admin.setUpdateTime(LocalDateTime.now());
  adminMapper.insertSelective(admin);
}

代码示例来源:origin: linlinjava/litemall

public int add(LitemallCollect collect) {
  collect.setAddTime(LocalDateTime.now());
  collect.setUpdateTime(LocalDateTime.now());
  return collectMapper.insertSelective(collect);
}

代码示例来源:origin: linlinjava/litemall

public int add(LitemallAddress address) {
  address.setAddTime(LocalDateTime.now());
  address.setUpdateTime(LocalDateTime.now());
  return addressMapper.insertSelective(address);
}

代码示例来源:origin: lets-blade/blade

@Test
public void testLocal(){
  Map<String,Object> result = new HashMap<>(8);
  result.put("date1", new Date());
  result.put("date2", LocalDate.now());
  result.put("date3", LocalDateTime.now());
  System.out.println(JsonKit.toString(result));
}

代码示例来源:origin: lets-blade/blade

public HttpServerInitializer(SslContext sslCtx, Blade blade, ScheduledExecutorService service) {
  this.sslCtx = sslCtx;
  this.blade = blade;
  this.useGZIP = blade.environment().getBoolean(Const.ENV_KEY_GZIP_ENABLE, false);
  this.isWebSocket = blade.routeMatcher().getWebSockets().size() > 0;
  this.httpServerHandler = new HttpServerHandler();
  service.scheduleWithFixedDelay(() -> date = DateKit.gmtDate(LocalDateTime.now()), 1000, 1000, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: lets-blade/blade

public HttpServerInitializer(SslContext sslCtx, Blade blade, ScheduledExecutorService service) {
  this.sslCtx = sslCtx;
  this.blade = blade;
  this.useGZIP = blade.environment().getBoolean(Const.ENV_KEY_GZIP_ENABLE, false);
  this.isWebSocket = blade.routeMatcher().getWebSockets().size() > 0;
  this.httpServerHandler = new HttpServerHandler();
  service.scheduleWithFixedDelay(() -> date = DateKit.gmtDate(LocalDateTime.now()), 1000, 1000, TimeUnit.MILLISECONDS);
}

代码示例来源:origin: lets-blade/blade

@Schedule(cron = "* * * * * ?")
public void run1(TaskContext context) {
  if (run1.get() == 5) {
    context.stop();
    return;
  }
  run1.getAndIncrement();
  log.info(LocalDateTime.now() + ": Hello task1. " + Thread.currentThread());
}

代码示例来源:origin: lets-blade/blade

@Schedule(cron = "* * * * * ?", name = "RUN3")
public void run3() {
  if (run3.get() == 3) {
    TaskManager.stopTask("RUN3");
    return;
  }
  run3.getAndIncrement();
  log.info(LocalDateTime.now() + ": Hello RUN3. " + Thread.currentThread());
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldFailWhenLocalDateTimeIsSentWithRun() throws Exception
{
  testFailureWithV2Value( ValueUtils.of( LocalDateTime.now() ), "LocalDateTime" );
}

代码示例来源:origin: lets-blade/blade

@Test
public void test2(){
  TestBean testBean = new TestBean();
  testBean.setDateTime(LocalDateTime.now());
  System.out.println(JsonKit.toString(testBean));
}

代码示例来源:origin: lets-blade/blade

@Test
public void testPrettyTime() {
  Assert.assertEquals("去年", DateKit.prettyTime(LocalDateTime.now().plusYears(-1), Locale.CHINESE));
  Assert.assertEquals("上个月", DateKit.prettyTime(LocalDateTime.now().plusMonths(-1), Locale.CHINESE));
  Assert.assertEquals("上周", DateKit.prettyTime(LocalDateTime.now().plusWeeks(-1), Locale.CHINESE));
  Assert.assertEquals("昨天", DateKit.prettyTime(LocalDateTime.now().plusDays(-1), Locale.CHINESE));
  Assert.assertEquals("1小时前", DateKit.prettyTime(LocalDateTime.now().plusHours(-1), Locale.CHINESE));
  Assert.assertEquals("1分钟前", DateKit.prettyTime(LocalDateTime.now().plusMinutes(-1), Locale.CHINESE));
  Assert.assertEquals("刚刚", DateKit.prettyTime(LocalDateTime.now().plusSeconds(-1), Locale.CHINESE));
  Assert.assertEquals("10秒前", DateKit.prettyTime(LocalDateTime.now().plusSeconds(-10), Locale.CHINESE));
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldCallExternalErrorOnLocalDateTime() throws Exception
{
  assumeThat( packerUnderTest.version(), equalTo( 1L ) );
  testUnpackableStructParametersWithKnownType( new Neo4jPackV2(), ValueUtils.of( LocalDateTime.now() ),
      "LocalDateTime values cannot be unpacked with this version of bolt." );
}

代码示例来源:origin: linlinjava/litemall

public int updateCheck(Integer userId, List<Integer> idsList, Boolean checked) {
  LitemallCartExample example = new LitemallCartExample();
  example.or().andUserIdEqualTo(userId).andProductIdIn(idsList).andDeletedEqualTo(false);
  LitemallCart cart = new LitemallCart();
  cart.setChecked(checked);
  cart.setUpdateTime(LocalDateTime.now());
  return cartMapper.updateByExampleSelective(cart, example);
}

相关文章

LocalDateTime类方法