#18
Beitrag
von MickeyMouse » Fr 05 Nov 2004, 17:22
@jmittelst - Soweit ich mich erinnere gibt es Windows Api Funktionen die unter allen Windows Funktionen einheitlich sind. Bei Unix und Java kenn ich mich nicht aus, aber die MAsse hat doch noch Windows als Client Sysem auf dem Desktop, so dass man hier mehr Komfort hätte.
Das mit der Liste mit den genauen Daten der Zeitumstellungs ist unnötig. Ich erwarte vom Betriebssystem, dass es die Uhr automatisch stellt und das tut es ja auch. Falls es politisch Änderungen geben sollte, ist das uch kein Problem, da es sicher Updates geben würde für das Betriebssystem (Windws, Lunux) rechtzeitig, bevor die Umstallung kommt. Und wenn nicht ist es auch egal, dann kann man ja imer noch manuell nachregeln, bis die Updates kommen.
Hier der Code für Daylight Saving Time (Sommerzeit):
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>
void main()
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };
/* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value
* for the variable.
*/
_tzset();
/* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate( tmpbuf );
printf( "OS date:\t\t\t\t%s\n", tmpbuf );
/* Get UNIX-style time and display as number and string. */
time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) );
/* Display UTC. */
gmt = gmtime( <ime );
printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );
/* Convert to time structure and adjust for PM if necessary. */
today = localtime( <ime );
if( today->tm_hour > 12 )
{
strcpy( ampm, "PM" );
today->tm_hour -= 12;
}
if( today->tm_hour == 0 ) /* Adjust if midnight hour. */
today->tm_hour = 12;
/* Note how pointer addition is used to skip the first 11
* characters and printf is used to trim off terminating
* characters.
*/
printf( "12-hour time:\t\t\t\t%.8s %s\n",
asctime( today ) + 11, ampm );
/* Print additional time information. */
_ftime( &tstruct );
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in seconds from UTC:\t%u\n",
tstruct.timezone );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
printf( "Daylight savings:\t\t\t%s\n",
tstruct.dstflag ? "YES" : "NO" );
/* Make time for noon on Christmas, 1993. */
if( mktime( &xmas ) != (time_t)-1 )
printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );
/* Use time structure to build a customized time string. */
today = localtime( <ime );
/* Use strftime to build a customized time string. */
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", today );
printf( tmpbuf );
}
Output
OS time: 21:51:03
OS date: 05/03/94
Time in seconds since UTC 1/1/70: 768027063
UNIX time and date: Tue May 03 21:51:03 1994
Coordinated universal time: Wed May 04 04:51:03 1994
12-hour time: 09:51:03 PM
Plus milliseconds: 279
Zone difference in seconds from UTC: 480
Time zone name:
Daylight savings: YES
Christmas Sat Dec 25 12:00:00 1993
Today is Tuesday, day 03 of May in the year 1994.
Also nur die Stelle angucken, wo "Daylight Savings steht". Da das für Windows und Unix gilt fehlt nur noch Java. Wenn da einer was weiß, kann er es ja posten.
Hier die 3 entscheideden Zeilen zum Testen für Windows und Unix:
struct _timeb tstruct;
_ftime (&tstruct);
printf ("Daylight savings: %s\n", tstruct.dstflag ? "YES" : "NO" );
Immer noch zu viel Aufwand?
Liebe Grüße
Eure Mickey Mouse
_______________________________________________________
Nokia Kabel, 2xI, aktuelles JtG Team Image und neuseter Snapshot
SAGEM Kabel, 2xI, aktuelles JtG Team Image und neuseter Snapshot
Software: WinXP Pro SP2, DVD-Lab Pro, Roxio Easy Media Creator 7.5, TEMPEnc
Hardware: P IV, 3 GHZ HT, 2 GB RAM, LG 4163B