Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ How to turn Java String into Date     - Linux Network Statistics Tools / Command (Linux)

- To use iostat display I / O status under Linux (Linux)

- To install and deploy Apache under the CentOS (Server)

- Oracle view object space usage show_space (Database)

- Ubuntu 14.04 install the NVIDIA driver + CUDA + MATLAB (Linux)

- Teach you the Ubuntu Server enabled SSH multifactor authentication (Server)

- CentOS 7 server environment to quickly build Linux (Server)

- How to manage your to-do list with the Go For It on Ubuntu (Linux)

- Oracle 11g modify MEMORY_TARGET (Database)

- Spring-depth understanding of the various annotations (Programming)

- Nginx installation configuration Zabbix (Server)

- Linux server data backup (Server)

- Linux development management utility command (Linux)

- RM Environment Database RMAN Backup Strategy Formulation (Database)

- Modular JavaScript (Programming)

- HA-Federation-HDFS + Yarn cluster deployment (Server)

- Oracle 10g, 11g database silent installation of small differences (Database)

- Lenovo E431 notebook CentOS system is installed wireless network card driver (Linux)

- After restarting network services, DNS address failure (Linux)

- Linux iptables port mapping settings (Server)

 
         
  How to turn Java String into Date
     
  Add Date : 2017-01-08      
         
       
         
  Recently discovered spring mvc and Jackson on Date type of support is not particularly good, although the Java object serialization Json data into the process provides a convenient annotation, but deserialization but in developing Json data deserialized into Java objects when no, so he begs the following question, I need to manually convert the string to Date data type, java.text.SimpleDateFormat provides us with the infrastructure of such conversion. Simply defined as a list of formatted mode, if the 'M' not less than three, month is displayed as the letter, otherwise it is digital. Please refer to a more detailed definition java.text.SimpleDateFormat JavaDoc.

Letter Description Examples
y Year 2015
M Month in year Nov, 11, 7
d Day in month 1-31
E Day name in week Friday, Sunday
a Am / pm marker AM, PM
H Hour in day 0-23
h Hour in am / pm 1-12
m Minute in hour 0-60
s Second in minute 0-60

 

1. Date = 7-Nov-2015

    SimpleDateFormat formatter = new SimpleDateFormat ( "dd-MMM-yyyy");
    String dateInString = "7-Nov-2015";

    try {

        Date date = formatter.parse (dateInString);
        System.out.println (date);
        System.out.println (formatter.format (date));

    } Catch (ParseException e) {
        e.printStackTrace ();
    }
    
Output

Mon Nov 07 00:00:00 MYT 2015
07-Nov-2015


2. Date = 07/06/2015

    SimpleDateFormat formatter = new SimpleDateFormat ( "dd / MM / yyyy");
    String dateInString = "07/06/2015";

    try {

        Date date = formatter.parse (dateInString);
        System.out.println (date);
        System.out.println (formatter.format (date));

    } Catch (ParseException e) {
        e.printStackTrace ();
    }
    
Output
Mon Nov 07 00:00:00 MYT 2015
07/06/2015

3. Date = Nov 7, 2015

    SimpleDateFormat formatter = new SimpleDateFormat ( "MMM dd, yyyy");
    String dateInString = "Nov 7, 2015";

    try {

        Date date = formatter.parse (dateInString);
        System.out.println (date);
        System.out.println (formatter.format (date));

    } Catch (ParseException e) {
        e.printStackTrace ();
    }
Output

Mon Nov 07 00:00:00 MYT 2015
Nov 07, 2015

4. Date = Fri, Nov 7 2015

    SimpleDateFormat formatter = new SimpleDateFormat ( "E, MMM dd yyyy");
    String dateInString = "Fri, Nov 7 2015";
        
    try {

        Date date = formatter.parse (dateInString);
        System.out.println (date);
        System.out.println (formatter.format (date));

    } Catch (ParseException e) {
        e.printStackTrace ();
    }
    
Output
Mon Nov 07 00:00:00 MYT 2015
Mon, Nov 07 2015

 
2. Date and Time Example
1. Date and Time = Friday, Nov 7, 2015 12:10:56 PM

    SimpleDateFormat formatter = new SimpleDateFormat ( "EEEE, MMM dd, yyyy HH: mm: ss a");
    String dateInString = "Friday, Nov 7, 2015 12:10:56 PM";
        
    try {

        Date date = formatter.parse (dateInString);
        System.out.println (date);
        System.out.println (formatter.format (date));

    } Catch (ParseException e) {
        e.printStackTrace ();
    }
    
Output
Mon Nov 07 12:10:56 MYT 2015
Monday, Nov 07, 2015 12:10:56 PM

to sum up
This paper briefly summarizes the string into Java objects mainstream method, we want to help.
     
         
       
         
  More:      
 
- Java string equal size comparison (Programming)
- Ubuntu Server 14.04 installation Web server (Linux + Apache + MySQL + PHP) (Server)
- Simple to install Tor browser to Ubuntu 14.04 and Linux Mint 17 (Linux)
- stat Usage: Get permission to file the corresponding figures (Linux)
- Django Web dynamic three linkage (Programming)
- Fedora 22 Server how to upgrade to Fedora 23 Beta Server (Linux)
- To solve the Mac in question invalid BASH under configuration environment variable (Linux)
- How to experience Unity 8 Mir on Ubuntu 16.04 (Linux)
- Oracle capability i / o (stress test database server i / o performance) (Database)
- Linux, Eclipse flash back and reinstall the JDK methods (Linux)
- Oracle 11g contraction table space error ORA-03297: file contains used data beyondrequested RESIZE value (Database)
- Linux resource restriction level summary (Linux)
- Spark local development environment to build (Server)
- After installing Ubuntu 15.04, to do a few things (Linux)
- Try debugfs restore the deleted files ext3 file system (Linux)
- Java garbage collection and heap memory layout (Programming)
- Go powerful development server simple example (Server)
- Oracle LONG RAW BLOB CLOB type of presentation (Database)
- C ++ input and output summary _ Input (Programming)
- RAID disk array Description (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.