当前位置: 首页 > news >正文

惠东住房建设局网站阳光保险网站

惠东住房建设局网站,阳光保险网站,西部数码网站助手 安装,企业官网首页模板Java日期工具类LocalDateTime 嘚吧嘚LocalDateTime - API创建时间获取年月日时分秒增加时间减少时间替换时间日期比较 嘚吧嘚 压轴的来了#xff0c;个人感觉LocalDateTime是使用频率最高的工具类#xff0c;所以本篇像文章详细研究说明一下#x1f9d0;。 如果看了Java日期… Java日期工具类LocalDateTime 嘚吧嘚LocalDateTime - API创建时间获取年月日时分秒增加时间减少时间替换时间日期比较 嘚吧嘚 压轴的来了个人感觉LocalDateTime是使用频率最高的工具类所以本篇像文章详细研究说明一下。 如果看了Java日期工具类LocalDate和Java时间工具类LocalTime那么本篇文章就算是一个整合、进阶吧。 LocalDateTime - API 创建时间 函数声明描述static LocalDateTime now()获取默认时区的当前日期时间static LocalDateTime now(ZoneId zone)获取指定时区的当前日期时间static LocalDateTime now(Clock clock)从指定时钟获取当前日期时间static LocalDateTime of(LocalDate date, LocalTime time)根据日期和时间对象获取LocalDateTime对象static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second)根据指定的年、月、日、时、分、秒获取LocalDateTime实例 LocalDateTime now() 获取指定时区、时钟的日期时间就不多做说明了和LocalDate一样。 // 获取当前时间 LocalDateTime now LocalDateTime.now(); System.out.println(now : now); // 格式化 DateTimeFormatter formatter DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss); String nowStr now.format(formatter); System.out.println(nowStr : nowStr);LocalDateTime of() 获取年月日时分秒 函数声明描述int getYear()获取年份Month getMonth()获取月份返回值为月份的枚举int getMonthValue()获取月份返回值为int类型月份DayOfWeek getDayOfWeek()获取日期是星期几int getDayOfMonth()获取日期在该月是第几天int getDayOfYear()获取日期在该年是第几天int getHour()获取小时int getMinute()获取分钟int getSecond()获取秒钟int getNano()获取纳秒 LocalDateTime now LocalDateTime.now(); // 获取年 System.out.println(getYear : now.getYear()); // 获取月份 System.out.println(getMonth : now.getMonth()); System.out.println(getMonthValue : now.getMonthValue()); // 获取日 System.out.println(getDayOfWeek : now.getDayOfWeek()); System.out.println(getDayOfMonth : now.getDayOfMonth()); System.out.println(getDayOfYear : now.getDayOfYear()); // 获取小时 System.out.println(getHour : now.getHour()); // 获取分钟 System.out.println(getMinute : now.getMinute()); // 获取秒 System.out.println(getSecond : now.getSecond()); // 获取纳秒 System.out.println(getNano : now.getNano());增加时间 虽然是增加时间传参可为正数也可为负数。传参为正数时增加传参为负数时减少。 函数声明描述LocalDateTime plusYears(long years)增加年LocalDateTime plusMonths(long months)增加月份LocalDateTime plusWeeks(long weeks)增加周LocalDateTime plusDays(long days)增加日LocalDateTime plusHours(long hours)增加小时LocalDateTime plusMinutes(long minutes)增加分钟LocalDateTime plusSeconds(long seconds)增加秒LocalDateTime plusNanos(long nanos)增加纳秒 增加年、月、周、日 LocalDateTime now LocalDateTime.now(); System.out.println(now: now); // 修改年份 System.out.println(plusYears : now.plusYears(1)); System.out.println(plusYears : now.plusYears(-1)); // 修改月份 System.out.println(plusMonths : now.plusMonths(1)); System.out.println(plusMonths : now.plusMonths(-2)); // 修改周 System.out.println(getDayOfWeek : now.plusWeeks(1)); System.out.println(getDayOfWeek : now.plusWeeks(-2)); // 修改日 System.out.println(plusDays : now.plusDays(3)); System.out.println(plusDays : now.plusDays(-3));增加时、分、秒、纳秒 LocalDateTime now LocalDateTime.now();System.out.println(now: now);// 修改小时System.out.println(plusHours : now.plusHours(2));System.out.println(plusHours : now.plusHours(-5));// 修改分钟System.out.println(plusMinutes : now.plusMinutes(20));System.out.println(plusMinutes : now.plusMinutes(-15));// 修改秒System.out.println(plusSeconds : now.plusSeconds(11));System.out.println(plusSeconds : now.plusSeconds(-31));// 修改纳秒System.out.println(plusNanos : now.plusNanos(53));System.out.println(plusNanos : now.plusNanos(-63));减少时间 虽然是减少时间传参可为正数也可为负数。传参为正数时减少传参为负数时增加。 函数声明描述LocalDateTime minusYears(long years)减少年LocalDateTime minusMonths(long months)减少月份LocalDateTime minusWeeks(long weeks)减少周LocalDateTime minusDays(long days)减少日LocalDateTime minusHours(long hours)减少小时LocalDateTime minusMinutes(long minutes)减少分钟LocalDateTime minusSeconds(long seconds)减少秒LocalDateTime minusNanos(long nanos)减少纳秒 减少其实也是调用的增加的方法 以减少年为例 LocalDateTime now LocalDateTime.now(); System.out.println(now: now); // 减少年 System.out.println(minusYears : now.minusYears(2)); System.out.println(minusYears : now.minusYears(-5));替换时间 函数声明描述LocalDateTime withYear(int year)替换年(-999999999-999999999)LocalDateTime withMonth(int month)替换月份(1-12)LocalDateTime withDayOfMonth(int dayOfMonth)替换为本月中的第几天(1-31)LocalDateTime withDayOfYear(int dayOfYear)替换为本年中的第几天(1-366)LocalDateTime withHour(int hour)替换小时(0-23)LocalDateTime withMinute(int minute)替换分钟(0-59)LocalDateTime withSecond(int second)替换秒(0-59)LocalDateTime withNano(int nanoOfSecond)替换纳秒(0-999999999) LocalDateTime now LocalDateTime.now(); System.out.println(now: now); // 替换年 System.out.println(withYear : now.withYear(1996)); // 替换月 System.out.println(withMonth : now.withMonth(5)); // 替换日 System.out.println(withDayOfMonth : now.withDayOfMonth(5)); System.out.println(withDayOfYear : now.withDayOfYear(5)); // 替换时 System.out.println(withHour : now.withHour(5)); // 替换分 System.out.println(withMinute : now.withMinute(5)); // 替换秒 System.out.println(withSecond : now.withSecond(5)); // 替换纳秒 System.out.println(withNano : now.withNano(5));日期比较 函数声明描述boolean isEqual(ChronoLocalDateTime? other)判断日期时间是否相等boolean isAfter(ChronoLocalDateTime? other)检查是否在指定日期时间之前boolean isBefore(ChronoLocalDateTime? other)检查是否在指定日期时间之后 DateTimeFormatter formatter DateTimeFormatter.ofPattern(yyyy-MM-dd HH:mm:ss); LocalDateTime time1 LocalDateTime.of(1999, 12, 5, 10, 12, 12); LocalDateTime time2 LocalDateTime.of(1999, 12, 6, 10, 12, 12); String timeStr1 time1.format(formatter); String timeStr2 time2.format(formatter); System.out.println(time1 : timeStr1); System.out.println(time2 : timeStr2); System.out.println(timeStr1 timeStr2 : time1.isEqual(time2)); System.out.println(timeStr1 timeStr2 : time1.isAfter(time2)); System.out.println(timeStr1 timeStr2 : time1.isBefore(time2));Java8新特性日期工具类的梳理到此结束欢迎大家补充说明。
http://www.w-s-a.com/news/981380/

相关文章:

  • 搜狐快站建站教程电子商务网站后台模板
  • .gs域名做网站怎么样做网站有没有用
  • 肇庆住房和城乡建设局网站广州seo公司排名
  • j2ee网站开发买什么书网络媒体有哪些
  • 江西省住房建设部官方网站用多说的网站
  • 云课堂哪个网站做的好网站 集约化平台建设方案的通知
  • 撰写网站栏目规划怎么建自己的平台
  • 中国建设银行巴黎分行网站建设银行忘记密码网站首页
  • 网站左侧树形导航怎么做像wordpress一样的网站吗
  • 做网站用的书公司做网站 需要解决哪些问题
  • 电器网站建设策划书深圳动画制作
  • cpa网站建设wordpress支付宝微信收费吗
  • 权威网站排名桂林生活网论坛
  • 网站设计息济南网站建设济南
  • 安蓉建设总公司网站网站怎么做才能被百度收录
  • 电子商务网站业务流程分析做效果图的外包网站
  • wordpress仿站视频教程wordpress用什么php版本好
  • 郑州做网站九零后网络沧州做网站的专业公司
  • 小游戏网站建设可以自己做图片的软件
  • 湖南地税局官网站水利建设基金app仿制
  • 苏州网站设计kgwl建设网站需要用到哪些技术人员
  • 万户网络做网站如何亚马逊网站建设
  • 门户网站制作费用暴雪公司最新消息
  • 深圳专业建网站公司济南公司做网站的价格
  • 怎么运行自己做的网站网上申请平台怎么申请
  • 旅游公司网站 优帮云新闻近期大事件
  • 电商网站后台报价营销软文小短文
  • 网站建设项目售后服务承诺公司名称邮箱大全
  • 湖南网站建设哪里好做ppt的网站叫什么名字
  • 容城县建设银行网站电子商务网站建设子项目