date.toString ... format

09.10.2007, 23:34
Citationimport java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;

public class DateFormatExample4 {

public static void main(String[] args) {
// Make a new Date object. It will be initialized to the
// current time.
Date now = new Date();

// Print the result of toString()
String dateString = now.toString();
System.out.println(" 1. " + dateString);

// Make a SimpleDateFormat for toString()'s output. This
// has short (text) date, a space, short (text) month, a space,
// 2-digit date, a space, hour (0-23), minute, second, a space,
// short timezone, a final space, and a long year.
SimpleDateFormat format =
new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy&quot ;) ;

// See if we can parse the output of Date.toString()
try {
Date parsed = format.parse(dateString);
System.out.println(" 2. " + parsed.toString());
}
catch(ParseException pe) {
System.out.println("ERROR: Cannot parse \"" + dateString + "\"&quot ;) ;
}

// Print the result of formatting the now Date to see if the result
// is the same as the output of toString()
System.out.println(" 3. " + format.format(now));
}
}


en sortie

Citation> java DateFormatExample4
1. Tue Nov 04 21:53:43 EST 2003
2. Tue Nov 04 21:53:43 EST 2003
3. Tue Nov 04 21:53:43 EST 2003
mumuri cinemona.com
mumuri
mumuri
Messages : 14 377

  • livres bds roman
  • allo ciné
  • astuces de jeux vidéos
  • forum
  • dessin animé
  • avis livres
  • avis films & streaming
  • séries télé
  • smileys
  • bourse
  • actualité de jeux vidéos
  • anime
Tous droits réservés © 2002-2009 . Top flood. Crédits des logiciels tiers     .