Java8时间转换
===java8中时间的各种转换(LocalDateTime)===
1.将LocalDateTime转为自定义的时间格式的字符串
public static String getDateTimeAsString(LocalDateTime localDateTime, String format) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
return localDateTime.format(formatter);
}
2.将long类型的timestamp转为LocalDateTime
public static LocalDateTime getDateTimeOfTimestamp(long timestamp) {
Instant instant = Instant.ofEpochMilli(timestamp);
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
}
3.将LocalDateTime转为long类型的timestamp
public static long getTimestampOfDateTime(LocalDateTime localDateTime) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return instant.toEpochMilli();
}
4.将某时间字符串转为自定义时间格式的LocalDateTime
public static LocalDateTime parseStringToDateTime(String time, String format) {
DateTimeFormatter df = DateTimeFormatter.ofPattern(format);
return LocalDateTime.parse(time, df);
}
链接:https://blog.csdn.net/wsywb111/article/details/79815481
Java8时间转换的更多相关文章
- java8 时间使用
为什么需要新的时间API 文章来源:https://www.cnblogs.com/guozp/p/10342775.html 在Java 8之前的日期/时间API之前,现有的与日期和时间相关的类存在 ...
- Java8 时间日期类操作
Java8 时间日期类操作 Java8的时间类有两个重要的特性 线程安全 不可变类,返回的都是新的对象 显然,该特性解决了原来java.util.Date类与SimpleDateFormat线程不安全 ...
- Java日期时间API系列21-----Jdk8中java.time包中的新的日期时间API类,xk-time时间转换,计算,格式化,解析的工具
通过工作之余,对Java8中java.time包源码的不断学习,使用和总结,开发了xk-time,初步完成,欢迎试用和提出建议! xk-time xk-time is a datetime conve ...
- 迄今为止最硬核的「Java8时间系统」设计原理与使用方法
为了使本篇文章更容易让读者读懂,我特意写了上一篇<任何人都需要知道的「世界时间系统」构成原理,尤其开发人员>的科普文章.本文才是重点,绝对要读,走起! Java平台时间系统的设计方案 几乎 ...
- [jquery]将当前时间转换成yyyymmdd格式
如题: function nowtime(){//将当前时间转换成yyyymmdd格式 var mydate = new Date(); var str = "" + mydate ...
- MySQL 日期、时间转换函数
MySQL 日期.时间转换函数:date_format(date,format), time_format(time,format) 能够把一个日期/时间转换成各种各样的字符串格式.它是 str_to ...
- java时间类型的转换/获取当前时间/将时间转换成String/将String转换成时间
对于我的脑子,我已经服气了...写了N遍的东西,就是记不住...既然记不住那就记下来... 利用java获取当前的时间(String类型,年-月-日 时:分:秒) //我要获取当前的日期 Date d ...
- inner join ,left join ,right join 以及java时间转换
1.inner join ,left join 与 right join (from 百度知道) 例表aaid adate1 a12 a23 a3表bbid bdate1 ...
- Python基本时间转换
时间转换 python中处理时间的时候,最常用的就是字符形式与时间戳之间的转换. 把最基本的转换在这里记下来 string -> timestamp import time import dat ...
随机推荐
- c博客作业01--顺序分支结构
0.展示PTA总分 1.本章学习总结 1.1 学习内容总结 1.运算符需注意的要点 '/'的左右两边如果均为整型数,其结果也为整型:'%'的左右两边只能为整型数: 优先级:逻辑运算符<关系运算符 ...
- GoCN每日新闻(2019-10-10)
GoCN每日新闻(2019-10-10) GoCN每日新闻(2019-10-10) 1. Go语言源码阅读之bytes.Buffer http://www.pengrl.com/p/60618/ 2. ...
- php在Linux下的相对路径问题
如图所示,我在 /root/phpcode/ 下面有两个php文件. a.php 与 b.php,我用 a.php 去 require b.php ,然后 b.php 输出 1. 现在我在 /root ...
- Git命令相关
特别说明 关于命令行中参数前面的-和--的区别 - 通常后面接参数的缩写 -- 通常后面接参数的全拼 eg: git status --short 等价于 git status -s 常用命令 创建版 ...
- 基于hive的《反贪风暴4》的影评
一:将爬虫大作业产生的csv文件上传到HDFS 查看文件中前10条信息,即可证明是否上传成功. 二.对CSV文件进行预处理生成无标题文本文件 创建一个deal.sh,主要实现数据分割成什么样的意思 执 ...
- 基于Hive的对BiliBili用户信息进行数据分析
用户表字段信息: 1.查出前1000位用户的用户名,关注数和粉丝数. 2.查询关注数大于100的用户的用户名和关注数. 3.查询粉丝数大于100的用户的用户名,粉丝数. 4.查询id为1000的用户的 ...
- how does SELECT TOP works when no order by is specified?
how does SELECT TOP works when no order by is specified? There is no guarantee which two rows you ge ...
- Attention U-Net: Learning Where to Look for the Pancreas
Attention U-Net: Learning Where to Look for the Pancreas 2019-09-10 09:50:43 Paper: https://arxiv.or ...
- dubbo、zookeeper心跳相关参数解析与测试
dubbo consumer和provider的心跳机制 dubbo客户端和dubbo服务端之间存在心跳,目的是维持provider和consumer之间的长连接.由dubbo客户端主动发起,可参见d ...
- Spring MVC -- MVC设计模式(演示4个基于MVC框架的案例)
对于简单的Java Web项目,我们的项目仅仅包含几个jsp页面,由于项目比较小,我们通常可以通过链接方式进行jsp页面间的跳转. 但是如果是一个中型或者大型的项目,上面那种方式就会带来许多维护困难, ...