Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SimpleDateFormat example
11-12-2009, 02:32 PM (This post was last modified: 11-12-2009 02:34 PM by codecaine.)
Post: #1
SimpleDateFormat example
This is a example of how you can format date and time using the SimpleDateFormat class.

Code:
//import SimpleDateFormat class and date class
import java.text.SimpleDateFormat;
import java.util.Date;

public class SimpleParse {

    public static void main(String[] args) {
        //initialize date to the current date and time
        Date today = new Date();

        //initialize SimpleDateFormat with a date format
        SimpleDateFormat sf = new SimpleDateFormat("d MMM y");

        //print out date
        System.out.println("Todays Date is: " + sf.format(today));

        //apply a new pattern for the time
        sf.applyPattern("h:mm a");
      
        //display formated time
        System.out.println("The Current time is: " + sf.format(today));
    }

}
Information about the SimpleDateFormat class can be located here: Java SimpleDateFormat() patterns
Visit this user's website Find all posts by this user
Quote this message in a reply
11-12-2009, 08:00 PM
Post: #2
RE: SimpleDateFormat example
Very good code, date and time formatting is good to write, i mean algorithmic !
But using libs is okay !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
12-09-2009, 08:20 AM
Post: #3
RE: SimpleDateFormat example
Code:
import java.text.SimpleDateFormat;
import java.util.Date;
useful things.
thanks.

[Image: 45669_pythonlogo.png][Image: 45668_javalogo.png]
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: