作者 shenhailong

航班计划解析入库 航班航程解析入库

@@ -3,12 +3,14 @@ package com.tianbo.util.Date; @@ -3,12 +3,14 @@ package com.tianbo.util.Date;
3 import javafx.util.converter.LocalDateTimeStringConverter; 3 import javafx.util.converter.LocalDateTimeStringConverter;
4 4
5 import java.text.ParseException; 5 import java.text.ParseException;
  6 +import java.text.ParsePosition;
6 import java.text.SimpleDateFormat; 7 import java.text.SimpleDateFormat;
7 import java.time.*; 8 import java.time.*;
8 import java.time.format.DateTimeFormatter; 9 import java.time.format.DateTimeFormatter;
9 import java.time.format.DateTimeParseException; 10 import java.time.format.DateTimeParseException;
10 import java.util.Calendar; 11 import java.util.Calendar;
11 import java.util.Date; 12 import java.util.Date;
  13 +import java.util.TimeZone;
12 14
13 15
14 /** 16 /**
@@ -102,6 +104,7 @@ public final class DateUtil { @@ -102,6 +104,7 @@ public final class DateUtil {
102 * @throws DateTimeParseException 104 * @throws DateTimeParseException
103 */ 105 */
104 public static Date formatByyyyyMMddHHmmss(String dateStr) throws DateTimeParseException{ 106 public static Date formatByyyyyMMddHHmmss(String dateStr) throws DateTimeParseException{
  107 + if (dateStr.length()>0){
105 //毫秒级的去掉 108 //毫秒级的去掉
106 if(dateStr.length()>14){ 109 if(dateStr.length()>14){
107 dateStr= dateStr.substring(0,14); 110 dateStr= dateStr.substring(0,14);
@@ -110,6 +113,8 @@ public final class DateUtil { @@ -110,6 +113,8 @@ public final class DateUtil {
110 LocalDateTime dateTime = LocalDateTime.parse(dateStr, formatter); 113 LocalDateTime dateTime = LocalDateTime.parse(dateStr, formatter);
111 return convertLDTToDate(dateTime); 114 return convertLDTToDate(dateTime);
112 } 115 }
  116 + return null;
  117 + }
113 118
114 //LocalDateTime转换为Date 119 //LocalDateTime转换为Date
115 public static Date convertLDTToDate(LocalDateTime time) { 120 public static Date convertLDTToDate(LocalDateTime time) {
@@ -540,4 +545,35 @@ public final class DateUtil { @@ -540,4 +545,35 @@ public final class DateUtil {
540 545
541 return time; 546 return time;
542 } 547 }
  548 +
  549 + /**
  550 + *
  551 + * @doc 日期转换星期几
  552 + * @param datetime
  553 + * 日期 例:2017-10-17
  554 + * @return String 例:星期二
  555 + * @author lzy
  556 + * @history 2017年10月17日 上午9:55:30 Create by 【lzy】
  557 + */
  558 + public static String dateToWeek(String datetime) throws java.text.ParseException {
  559 + SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
  560 + f.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
  561 + f.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
  562 + String[] weekDays = { "7","1" , "2", "3", "4", "5", "6"};
  563 + Calendar cal = Calendar.getInstance(); // 获得一个日历
  564 + Date datet = null;
  565 + datet = (Date) f.parse(datetime);
  566 + cal.setTime(datet);
  567 + int w = cal.get(Calendar.DAY_OF_WEEK)-1; // 指示一个星期中的某天。
  568 + if (w < 0)
  569 + w = 0;
  570 + return weekDays[w];
  571 + }
  572 +
  573 + public static void main(String[] args) throws ParseException {
  574 + String s = dateToWeek("20200815");
  575 + System.out.println(s);
  576 + }
  577 +
  578 +
543 } 579 }