Java:LocalDate / LocalDateTime加减时间

在线API参考:LocalTime (Java Platform SE 8 )

方法介绍

方法1方法1说明
plusYears(long years) minusYears(long years) 返回增加/减少了年数的副本
plusMonths(long months)  minusMonths(long months)返回增加/减少了月数的副本
plusWeeks(long weeks) minusWeeks(long weeks) 返回增加/减少了周数的副本
plusDays(long days)minusDays(long days)返回增加/减少了天数的副本
plusHours(long hours)minusHours(long hours)返回增加/减少了小时数的副本
plusSeconds(long seconds)minusMinutes(long minutes)返回增加/减少了分钟数的副本
plusSeconds(long seconds) minusSeconds(long seconds)返回增加/减少了秒数的副本
plusNanos(long nanos)minusNanos(long nanos) 返回增加/减少了纳秒数的副本
public class BaseTest {public static void main(String[] args) throws ParseException {LocalDateTime localTime = LocalDateTime.now();System.out.println("当前时间: " + localTime);System.out.println("增加1年:" + localTime.plusYears(1));System.out.println("增加1个月:" + localTime.plusMonths(1));System.out.println("增加1周:" + localTime.plusWeeks(1));System.out.println("增加1天:" + localTime.plusDays(1));System.out.println("增加1小时: " + localTime.plusHours(1));System.out.println("增加30分钟: " + localTime.plusMinutes(30));System.out.println("增加30秒: " + localTime.plusSeconds(30));System.out.println("增加10000纳秒:" + localTime.plusNanos(10000));System.out.println("减少1年:" + localTime.minusYears(1));System.out.println("减少1个月:" + localTime.minusMonths(1));System.out.println("减少1周:" + localTime.minusWeeks(1));System.out.println("减少1天:" + localTime.minusDays(1));System.out.println("减少1小时:" + localTime.minusHours(1));System.out.println("减少30分钟:" + localTime.minusMinutes(30));System.out.println("减少30秒: " + localTime.minusSeconds(30));System.out.println("减少10000纳秒:" + localTime.minusNanos(10000));}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543957.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

集合 List 分片的 5 种实现

作者 | 磊哥来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)前些天在实现 MyBatis 批量插入时遇到了一个问题,当批量插入的数据量比较大时,会导致程序执行报错&a…

消失的死锁

问题描述 如果java层面发生了死锁,当我们使用jstack命令的时候其实是可以将死锁的信息给dump出来的,在dump结果的最后会有类似Found one Java-level deadlock:的关键字,接着会把发生死锁的线程的堆栈及对应的同步锁给打印出来,这次…

ruby 新建对象_Ruby中的面向对象编程

ruby 新建对象Before getting into understanding how Object-oriented programming is implemented in Ruby, let us first understand what Object Oriented means. 在了解如何在Ruby中实现面向对象的编程之前,让我们首先了解面向对象的含义。 Object-oriented p…

使用它给 ​xxl-job 添加任务,太爽了

xxl-job是一款非常优秀的任务调度中间件,轻量级、使用简单、支持分布式等优点,让它广泛应用在我们的项目中,解决了不少定时任务的调度问题。我们都知道,在使用过程中需要先到xxl-job的任务调度中心页面上,配置执行器ex…

dubboSPI机制浅谈

2019独角兽企业重金招聘Python工程师标准>>> 本文重点讲述SPI机制,从jdk和dubbo 1、jdk spi机制 2、dubbo spi实现 首先spi是什么? SPI是为某个接口寻找服务实现的机制。为了实现在模块装配的时候能不在…

python 类中静态变量_Python中的类或静态变量

python 类中静态变量Python类/静态变量 (Python Class / Static Variables) Class or Static variables are class-related variables that are shared among all objects but the instance or non-static variable is unique for each object. In Python, there is no need fo…

彻底搞懂 SpringBoot 中的 starter 机制

前言我们都知道,Spring的功能非常强大,但也有些弊端。比如:我们需要手动去配置大量的参数,没有默认值,需要我们管理大量的jar包和它们的依赖。为了提升Spring项目的开发效率,简化一些配置,Sprin…

android四大组件之Service 注册广播接收者

广播的注册一共有两种,一种就是用清单文件注册,还有另外一种就是用代码注册,代码注册比较灵活,可以在需要的时候注册,不需要的时候解除注册 用服务注册广播首先要开启服务, 然后在服务oncreate方法里注册广…

c ++向量库_将向量复制到C ++中的另一个向量

c 向量库The ways that we are using to copy vectors in C, are: 我们用于在C 中复制向量的方法是: Copy one vectors elements to another (Simple approach) 将一个向量的元素复制到另一个(简单方法) Copy vector by using an assignment operator 通过使用赋值…

Java 中验证时间格式的 4 种方法

大家好,今天咱们来讲一下,Java 中如何检查一个字符串是否是合法的日期格式?为什么要检查时间格式?后端接口在接收数据的时候,都需要进行检查。检查全部通过后,才能够执行业务逻辑。对于时间格式&#xff0c…

FreeSWITCH的TLS加密

听着很高大上(实际也很实用)的加密机制,在FreeSWITCH里配置支持竟然这么简单! Greate FreeSWITCH and Greate Programmer! ① cd /usr/local/freeswitch/bin(以默认的安装路径为例) ② 产生root…

kotlin 查找id_Kotlin程序查找Sphere的体积

kotlin 查找idFormula to find volume of Sphere: volume (4/3)*PI*r^3 查找球体体积的公式: volume (4/3)* PI * r ^ 3 Given the value of radius, we have to find the volume of Sphere. 给定半径的值,我们必须找到球体的体积。 Example: 例&#…

Redis 实现分布式锁的 7 种方案

前言日常开发中,秒杀下单、抢红包等等业务场景,都需要用到分布式锁。而Redis非常适合作为分布式锁使用。本文将分七个方案展开,跟大家探讨Redis分布式锁的正确使用方式。如果有不正确的地方,欢迎大家指出哈,一起学习一…

css复选框样式_使用CSS样式复选框

css复选框样式Introduction: 介绍: Sometimes we want to develop a website or web page that would contain a form and through that form, we want to get some information from the user. Now that information could be of any type depending on the kind …

大数据计算平台Spark内核全面解读

1、Spark介绍 Spark是起源于美国加州大学伯克利分校AMPLab的大数据计算平台,在2010年开源,目前是Apache软件基金会的顶级项目。随着Spark在大数据计算领域的暂露头角,越来越多的企业开始关注和使用。2014年11月,Spark在Daytona Gr…

javascript对话框_JavaScript中的对话框

javascript对话框JavaScript对话框 (JavaScript Dialog Boxes) Dialog boxes are a great way to provide feedback to the user when they submit a form. In JavaScript, there are three kinds of Dialog boxes, 对话框是向用户提交表单时提供反馈的好方法。 在JavaScript中…

排查死锁的 4 种工具,秀~

作者 | 磊哥来源 | Java中文社群(ID:javacn666)转载请联系授权(微信ID:GG_Stone)死锁(Dead Lock)指的是两个或两个以上的运算单元(进程、线程或协程)&#xf…

MySQL 常见的 9 种优化方法

大家好,我是磊哥!今天给大家分享一些简单好用的数据库优化方式!1、选择最合适的字段属性Mysql是一种关系型数据库,可以很好地支持大数据量的存储,但是一般来说,数据库中的表越小,在它上面执行的…

oracle中dbms_DBMS中的实例和架构

oracle中dbms1)实例 (1) Instances) What is the Instance? If we look towards it in real life, we refer instance as an occurrence of something at a particular moment of time. In Database Management system, there are a lot of changes occurring over time to th…

acess() 判断目录是否存在

acess()功能描述&#xff1a; 检查调用进程是否可以对指定的文件执行某种操作。 <pre lang"c" escaped"true">#include <unistd.h>int access(const char *pathname, int mode); </pre>参数说明&#xff1a;pathname: 需要测试的文件路径…