Dieses Beispiel teilt den spezifischen Code für Java mit, um die Konvertierung zwischen Zeit und Zeichenfolgen für Ihre Referenz zu implementieren. Der spezifische Inhalt ist wie folgt
1. Konvertieren Sie die lange Saite in Yyyy-MM-DD HH: MM: SS-Formatausgabe
Java.Text.SimpledateFormat importieren; import Java.util.date; // Long String in Formatzeit ausgeben public class longoString {public static void main (String argsp []) {String time = "1256006105375"; Datum Datum = neues Datum (lang.Parselong (Uhrzeit)); SimpleDateFormat Formatter = new SimpledateFormat ("yyyy-mm-dd hh: mm: ss"); time = formatter.format (Datum); System.out.println (Zeit); }} 2. Konvertieren Sie die Zeichenfolge in die Zeit
Java.Text.SimpledateFormat importieren; import Java.util.date; importieren ognl.parseException; öffentliche Klasse StringTodate {public static void main (String argsp []) löst Ausnahme aus {String time = "2010-11-20 11:10:10"; Datum Datum = null; SimpleDateFormat Formatter = new SimpledateFormat ("yyyy-mm-dd hh: mm: ss"); Datum = Formatter.Parse (Zeit); System.out.println (Datum); }} 3. Holen Sie sich die aktuelle Systemzeit und geben Sie die YYYY-MM-DD HH: MM: SS-String zurück
Java.Text.SimpledateFormat importieren; import Java.util.date; public class StringTodate {public static void main (String argsp []) löst Ausnahme aus {Date date = new Date (); SimpleDateFormat Formatter = new SimpledateFormat ("yyyy-mm-dd hh: mm: ss"); String time = Formatter.format (Datum); System.out.println (Zeit); }} 4. Holen Sie sich die aktuelle Systemzeit und geben Sie die HH: MM: SS -Zeichenfolge zurück
Java.Text.SimpledateFormat importieren; import Java.util.date; public class StringTodate {public static void main (String argsp []) löst Ausnahme aus {Date date = new Date (); SimpleDateFormat Formatter = new SimpledateFormat ("HH: MM: SS"); String time = Formatter.format (Datum); System.out.println (Zeit); }} 5. Konvertieren Sie 20101125102503 bis 2010-11-25 10:25:03 Ausgabe
Java.Text.SimpledateFormat importieren; import Java.util.date; public class StringTodate {public static void main (String argsp []) löst Ausnahme aus {String time = "20101125102503"; SimpleDateFormat Formatter1 = new SimpledateFormat ("yyyy-hh-dd hh: mm: ss"); SimpleDateFormat Formatter2 = new SimpledateFormat ("yyyyhhdhhmms"); time = formatter1.Format (Formatter2.Parse (Zeit)); System.out.println (Zeit); }}Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.