Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

String in Date umwandeln

Empfohlene Antworten

Hallo,

ich möchte einen String in ein Date umwandeln. Ich kriege dabei jedoch immer eine Exception und sehe nicht warum. Normalerweise müsste es doch wie unten funktionieren?


    SimpleDateFormat cookieDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CEST' yyyy");

    String a = "Thu Aug 09 02:00:00 CEST 2012";

    Date b = cookieDateFormat.parse(a);

java.text.ParseException

Ich habe jetzt nach einigem Testen herausgefunden, dass das "EEE" im Pattern das Problem verursacht. Ein einzelnes E funktioniert auch nicht.

Den Grund dafür kann ich nicht verstehen, da es laut Dokumentation möglich ist. Siehe dazu SimpleDateFormat (Java 2 Platform SE v1.4.2)

Hi Scrhnd,

So:


import java.util.*;

import java.text.*;

...


SimpleDateFormat cookieDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss 'CEST' yyyy");


String a = "Thu Aug 09 02:00:00 CEST 2012";

Date b = cookieDateFormat.parse(a, new ParsePosition(0));

...kompiliert es (es sei denn, ich habe gerade eben einen Tippfehler gemacht). Der Fehler lag darin, dass die parse-Methode ein Parseposition-Objekt erfordert, das angibt, wo er anfangen soll, zu parsen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.