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.

Systemzeit auslesen

Empfohlene Antworten

Veröffentlicht

Hi Leute ich hab ein ziemlich einfaches Anliegen(was mich aber trotzdem in den Wahnsinn treibt:

import java.util.Date;


public class Systemzeit

{

  public static void main (String [] args)

  {

    Date date = new Date();

    System.out.println("Aktuelles Datum: " + date);

    System.out.println(date.getTime());

  }

}

Ich möchte nicht das ganze Datum ausegeben sondern nur Stunde Minute Sekunde.

Habs schon versucht mit

System.out.println(date.getSecond); u.s.w.

aber da bekomme ich nur Fehlermeldungen. Welche Methode gibt es mit der das geht?

sieht viel aus, isses aber nich, einfach nur kopieren und entsprechende imports setzen

import java.util.*;

...

String strTimeStamp = new String("");

// create a Europe Standard Time time zone

SimpleTimeZone pdt = new SimpleTimeZone(

   3600000, "Europe/Paris", Calendar.MARCH, -1, Calendar.SUNDAY, 3600000,

   SimpleTimeZone.UTC_TIME, Calendar.OCTOBER, -1, Calendar.SUNDAY,

   3600000, SimpleTimeZone.UTC_TIME, 3600000);

Calendar calendar = new GregorianCalendar(pdt);

Date trialTime = new Date();

trialTime.setTime(System.currentTimeMillis());

calendar.setTime(trialTime);

//format the date

if (calendar.get(Calendar.HOUR_OF_DAY) < 10)

   strTimeStamp = "0" + calendar.get(Calendar.HOUR_OF_DAY);

else

   strTimeStamp = "" + calendar.get(Calendar.HOUR_OF_DAY);


if (calendar.get(Calendar.MINUTE)<10)

   strTimeStamp = strTimeStamp + ":0" + calendar.get(Calendar.MINUTE); 

else

   strTimeStamp = strTimeStamp + ":" + calendar.get(Calendar.MINUTE);


if (calendar.get(Calendar.SECOND)<10)

   strTimeStamp = strTimeStamp + ":0" + calendar.get(Calendar.SECOND); 

else

   strTimeStamp = strTimeStamp + ":" + calendar.get(Calendar.SECOND);

return strTimeStamp;

hatte dieses problem letzte woche erst

so funktionierts, einfacher ist es nicht möglich

Ja klar, und den Osterhasen gibt es nicht. :floet: ;)

System.out.println(new SimpleDateFormat("HH:mm:ss").format(new Date()));

Gruß Jaraz

Ich sehe gerade, dass meine Angabe falsch war:

Die Lösung von Jaraz ist natürlich die Beste...

Die Lösung bei mir wäre so richtig:


String s = DateFormat.getDateInstance(DateFormat.LONG,Locale.GERMAN).format(date);

s += " "+DateFormat.getTimeInstance(DateFormat.LONG,Locale.GERMAN).format(date);


Berichtigt mich bitte falsch es wieder falsch ist!

du kannst es auch so machen:


Date date = new Date();

SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");

String myDateformated = sdf.format(date);

mfg byte

  • Autor

danke aber ich bereits die Methode von MKScheller durch ein paar weitere Methoden ergänzt und das erfüllt eigentlich meine Anforderungen ganz gut(schnell ist zwar nicht so sehr aber es muss auch nicht viel machen). :mod:

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.