KuoHsiangYu

解析日期字串1

Dec 4th, 2020
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package com.sample;
  2.  
  3. import static java.lang.System.err;
  4. import static java.lang.System.out;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7.  
  8. public class TestDate1 {
  9.  
  10.     public static void main(String[] args) {
  11.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd aa hh:mm");
  12.         String date1 = "2020-12-4 AM 10:4";
  13.         java.util.Date date = null;
  14.         try {
  15.             date = simpleDateFormat.parse(date1);
  16.         } catch (ParseException ex) {
  17.             ex.printStackTrace();
  18.         }
  19.         if (date != null) {
  20.             out.println(date.toLocaleString());
  21.         } else {
  22.             err.println("parse date error");
  23.         }
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment