LocalDateTime相关处理,得到零点以及24点值,最近五分钟点位,与Date互转,时间格式
最近一直使用LocalDateTime,老是忘记怎么转换,仅此记录一下
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date; public class Test { public static void main(String[] args) {
LocalDateTime now = LocalDateTime.now();
System.out.println("当前时间: "+now); //时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println("formate: "+ now.format(formatter)); //当天的零点
System.out.println("当天的零点: "+LocalDateTime.of(now.toLocalDate(), LocalTime.MIN)); //当天的最后时间
System.out.println("当天的最后时间: "+LocalDateTime.of(now.toLocalDate(), LocalTime.MAX)); //最近的五分钟点位
Integer minute = now.getMinute();
minute = minute/5*5;
System.out.println("最近的五分钟点位: "+LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), now.getHour(), minute, 0)); //Date转为LocalDateTime
Date date = new Date();
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
System.out.println("Date转为LocalDateTime: "+instant.atZone(zoneId).toLocalDateTime());
} }

LocalDateTime相关处理,得到零点以及24点值,最近五分钟点位,与Date互转,时间格式的更多相关文章
- ios 在中国地区,24小时时间格式 系统设定下 获得12小时制时间的方法
如题,在中国地区,24小时时间格式 系统设定下,如果单单使用 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 之后,无论用hh ...
- SimpleDateFormat转换时间,12,24时间格式[转]
SimpleDateFormat转换时间,12,24时间格式 来自:http://blog.csdn.net/dongguang1082/article/details/4387165 在使用Simp ...
- LocalDateTime与字符串互转/Date互转/LocalDate互转/指定日期/时间比较
Java 8中表示日期和时间的类有多个,主要的有: Instant:表示时刻,不直接对应年月日信息,需要通过时区转换 LocalDateTime: 表示与时区无关的日期和时间信息,不直接对应时刻,需要 ...
- Elasticsearch Date类型,时间存储相关说明
资料 网址 Elasticsearch 插入时间字段时数据格式问题 https://segmentfault.com/a/1190000016296983 Elasticsearch Date类型,时 ...
- Java中String、LocalDateTime、LocalDate、Date互转
String 转LocalDate和LocalDateTime LocalDate startDate = LocalDate.parse("2019-12-05", DateTi ...
- 时间戳和LocalDateTime和Date互转和格式化
一 前言 续上篇java8在日常开发中使用LocalDate和LocalTime[https://blog.csdn.net/youku1327/article/details/102771936]中 ...
- 【PTA】5-2 下列程序读入时间数值,将其加1秒后输出,时间格式为:hh: mm: ss,即“小时:分钟:秒”,当小时等于24小时,置为0。
5-2 下列程序读入时间数值,将其加1秒后输出,时间格式为:hh: mm: ss,即"小时:分钟:秒",当小时等于24小时,置为0. #include <stdio.h> ...
- SimpleDateFormat转换时间,12,24时间格式
Date d = new Date(); SimpleDateFormat ss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//1 ...
- 修改stl::set相关源码,提供有序属性值的查找接口
普通的stl::set,查找时只能传入key_type. 不能使用属性值查找. 例如: /* an employee record holds its ID, name and age */ clas ...
随机推荐
- Discuz! G变量的使用方法
1,G变量的使用方法: 例如:$_G['style'][boardlogo] 风格变量篇 $_G['style'] => Array (官方模板区 cr180整理 $_G['style'][st ...
- vs Could Not Connect
解决, 在win7上卸载IIS 10.0 Express ,安装 IIS7.5 Express
- Ajax无刷新显示
前台页面 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1. ...
- c#中动态创建textbox并且从数据库中获取表中数据添加到textbox中
private void FormLugOther_Load(object sender, EventArgs e) { foreach (string str in FormLug.FieldLis ...
- js 计算是今天多少周
/** * 判断年份是否为润年 * * @param {Number} year */ function isLeapYear(year) { return (year % 400 == 0) || ...
- Enable ssh root login in Solaris
1. Change the file /etc/ssh/sshd_config with PermitRootLogin yes to replace PermitRootLogin no 2. re ...
- 从0开始复习JS---1、函数复习
1. 写一个函数,实现对数字数组的排序. function get_order(array){ for(var i = 0; i <array.length-1; i++){ for(var j ...
- [luogu2594 ZJOI2009]染色游戏(博弈论)
传送门 Solution 对于硬币问题,结论是:当前局面的SG值等于所有背面朝上的单个硬币SG值的异或和 对于求单个背面朝上的硬币SG值...打表找规律吧 Code //By Menteur_Hxy ...
- Problem 42
Problem 42 https://projecteuler.net/problem=42 The nth term of the sequence of triangle numbers is g ...
- 远程连接工具putty与mtputty
PuTTY是一个Telnet.SSH.rlogin.纯TCP以及串行接口连接软件 官网 http://www.chiark.greenend.org.uk/~sgtatham/putty/ putty ...