惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 秦岭过客

BigDecimal SourceTree for Mac 不断弹出“输入密码”框 两组日期取交集 macbook 蓝牙关闭按钮灰色的 freemarker java BigDecimal pom.xml spring @Transactional注解参数详解 B树、B+树、二叉树、红黑树 Vector、List、LinkedList HashSet、HashMap、Hashtable、TreeMap循环、区别 java线程初写,陆续更新中。。 Thread的六中状态 mac shell mac 安装Sequel Pro JsonObject没有fromObject、idea引入maven有红线没依赖、JsonObject maven 依赖包 Error:java: Compilation failed: internal java compiler error idea 取消控制台的行数限制 【JXL】导出Excel
LocalDateTime、LocalDate、Long、Date、String 相互转换
秦岭过客 · 2019-08-07 · via 博客园 - 秦岭过客
DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter dateTimeFormatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");

LocalDateTime localDateTime = LocalDateTime.parse("2019-07-31 00:00:00",dateTimeFormatter1);
LocalDate localDate = LocalDate.parse("2019-07-31",dateTimeFormatter2);
Date date = Date.from(LocalDateTime.parse("2019-07-31 00:00:00",dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant());


String strDateTime = "2019-07-31 00:00:00";
String strDate = "2019-07-31";
Long timestamp=1564502400000l;

/** LocalDateTime 转 LocalDate */
System.out.println("LocalDateTime 转 LocalDate: "+localDateTime.toLocalDate());
/** LocalDateTime 转 Long */
System.out.println("LocalDateTime 转 Long: "+localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
/** LocalDateTime 转 Date */
System.out.println("LocalDateTime 转 Date: "+Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()));
/** LocalDateTime 转 String */
System.out.println("LocalDateTime 转 String: "+localDateTime.format(dateTimeFormatter1));

System.out.println("-------------------------------");

/** LocalDate 转 LocalDateTime */
System.out.println("LocalDate 转 LocalDateTime: "+LocalDateTime.of(localDate,LocalTime.parse("00:00:00")));
/** LocalDate 转 Long */
System.out.println("LocalDate 转 Long: "+localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());
/** LocalDate 转 Date */
System.out.println("LocalDate 转 Date: "+Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()));
/** LocalDate 转 String */
System.out.println("LocalDateTime 转 String: "+localDateTime.format(dateTimeFormatter2));

System.out.println("-------------------------------");

/** Date 转 LocalDateTime */
System.out.println("Date 转 LocalDateTime: "+LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()));
/** Date 转 Long */
System.out.println("Date 转 Long: "+date.getTime());
/** Date 转 LocalDate */
System.out.println("Date 转 LocalDateTime: "+LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).toLocalDate());
/** Date 转 String */
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS" );
System.out.println("Date 转 String: "+sdf.format(date));

System.out.println("-------------------------------");

/** String 转 LocalDateTime */
System.out.println("String 转 LocalDateTime: "+LocalDateTime.parse(strDateTime,dateTimeFormatter1));
/** String 转 LocalDate */
System.out.println("String 转 LocalDate: "+LocalDateTime.parse(strDateTime,dateTimeFormatter1).toLocalDate());
System.out.println("String 转 LocalDate: "+LocalDate.parse(strDate,dateTimeFormatter2));
/** String 转 Date */
System.out.println("String 转 Date: "+Date.from(LocalDateTime.parse(strDateTime,dateTimeFormatter1).atZone(ZoneId.systemDefault()).toInstant()));

System.out.println("-------------------------------");

/** Long 转 LocalDateTime */
System.out.println("Long 转 LocalDateTime:"+LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()));
/** Long 转 LocalDate */
System.out.println("Long 转 LocalDate:"+LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()).toLocalDate());
日期比较       
 LocalDateTime now = LocalDateTime.now();//2020-09-11T09:41:01.547
        LocalDateTime DiscountStartTime = now.minusDays(3);//减法 2020-09-08T09:41:01.547
        LocalDateTime DiscountEndTime = now.plusDays(3);//加法 2020-09-14T09:41:01.547

//        now>DiscountStartTime && DiscountEndTime>now
//        DiscountEndTime>now>DiscountStartTime
        if(now.isAfter(DiscountStartTime) && DiscountEndTime.isAfter(now)){
            true;//输出true
        }