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.

Empfohlene Antworten

Veröffentlicht

Tach!

Nur eine kurze Frage, in welchem Format kann ich Datum und Zeit ausgeben? Bei ganzen Zahlen ist es ja int un bei Kommazahlen double, aber nen Datum ist weder das eine noch das andere!! Ich find da nichts drüber und die Zeit will ich nicht nur als String ausgeben!

  • 2 Wochen später...

also mit zeit und datum ist das so eine sache *g*

hatte mir auch immer probleme in C bereitet. in C++ hab ich's noch nit benutzt.

hier is der code, den ich mir damals mal zusammengetippt hab.

das programm gibt jede sekunde die zeit aus wie lange es noch bis 19uhr am 15. des monats ist (hatte damals auf meine freundin gewartet die im urlaub war *g*)

im moment sieht die ausgabe so aus:


0 2:26:20

0 2:26:19

0 2:26:18

0 2:26:17

0 2:26:16

tage stunden:minuten:sekunden hier is der code:

#include <stdio.h>

#include <time.h>

#include <stdlib.h>


int main()

{

  time_t now_time;

  time_t later_time;

  double time_in_sec;

  double day;

  double hour;

  double min;

  double sec;


  struct tm *tm_time;


  now_time = time(&now_time);


  tm_time = localtime(&now_time);


  tm_time->tm_sec  = 0;

  tm_time->tm_min  = 0;

  tm_time->tm_hour = 19;

  tm_time->tm_mday = 15;


  later_time = mktime(tm_time);


  for(;

    {

      now_time = time(&now_time);


      time_in_sec = difftime(later_time, now_time);


      day = time_in_sec/60/60/24;

      //printf("days:  %d\n", (int)day);

      hour = (day - (int)day) * 24;

      //printf("hours: %d\n", (int)hour);

      min = (hour - (int)hour) * 60;

      //printf("mins:  %d\n", (int)min);

      sec = (min - (int)min) * 60;

      //printf("secs:  %d\n", (int)sec);


      printf("%d %d:%d:%d\n", (int)day, (int)hour, (int)min, (int)sec);


      //printf("%d %d\n", tm_time->tm_sec, tm_time->tm_mday);

      sleep(1);

    }


  return 0;

}[/code]

ich hoffe ich konnt dir helfen

Hallo,

warum so kompliziert? Die Standardblibliothek stellt die Funktion "strftime()" zur Verfügung. Damit lässt sich ein "struct tm *" in so ziemlich jedem nur erdenklichen Format ausgeben, ohne das man die einzelnen Bestandteile der Struktur zerlegen muss!

Nic

aber er wollte es doch nit als string, wie ich das verstanden hab.

wollte ihm nur zeigen, dass man es einfach auseinanderflücken kann, damit er seine zahlen hat. und nicht nur die strings.

Ich find da nichts drüber und die Zeit will ich nicht nur als String ausgeben!

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.