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.

SimpleDateFormat("yyyyMMddHHmmss") ->parse-> ("yyyy-MM-dd HH:mm:ss")

Empfohlene Antworten

Veröffentlicht

Hallo,

ich hab n prob.!!!

Ich habe eine "long" Zahl:

long zahl1 = 20090706131500l; // 2009.07.06 - 18:15:00 

Diese ist im Format ("yyyyMMddHHmmss")

Nun möchte ich diese long Zahl umwandeln in das Format ("yyyy-MM-dd HH:mm:ss") sollte am ende wieder vom typ "long" sein.

Hab schon gegoogelt und vieles mit "parse/parseObject" probiert. klappt aber nicht so wie ich will...

ich will einfach das hier erzwingen

->

Aus 20090706131500 werde 2009.07.06 - 18:15:00

Nun möchte ich diese long Zahl umwandeln in das Format ("yyyy-MM-dd HH:mm:ss") sollte am ende wieder vom typ "long" sein.
Was denn nun? Soll am Ende ein Datumsstring im Format "yyyy-MM-dd HH:mm:ss" herauskommen oder eine Long Zahl?

Generell ist die Umwandlung von Datumswerten von Format A nach Format B immer ein zweistufiger Prozess:

A) Parsen des Quell-Strings in java.util.Date über DateFormat#parse

B) Ausgabe im Zielformat über DateFormat#format

Genau!

ich habe eine long zahl "20090706131500l"

und aus der soll ein String gemacht werden im Format "yyyy-MM-dd HH:mm:ss"

ich habe eine long zahl "20090706131500l" und aus der soll ein String gemacht werden im Format "yyyy-MM-dd HH:mm:ss"
Und hast du dir schon die Verwendung von java.util.Date und java.util.DateFormat angesehen? Wenn nein: machen!


DateFormat inFormat = new SimpleDateFormat("yyyyMMdd...");

Date inDate = inFormat.parse("20090706...");

DateFormat outFormat = new SimpleDateFormat("yyyy-MM-....");

String outDate = outFormat.format(inDate);

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

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.