PROGRAM TimeZones_Math_3; //selftest of super functions with TimeZone API! //Task: get the interfaces of those functions from Help "All Functions List" (*typedef struct _SYSTEMTIME { WORD wYear; WORD wMonth; WORD wDayOfWeek; WORD wDay; WORD wHour; WORD wMinute; WORD wSecond; WORD wMilliseconds; } SYSTEMTIME, *PSYSTEMTIME; *) Const SKEY_NT = '\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\'; SKEY_9X = '\SOFTWARE\Microsoft\Windows\CurrentVersion\Time Zones\'; //Settings for each time zone are stored in the following registry key: {HKEY_LOCAL_MACHINE SOFTWARE Microsoft Windows NT CurrentVersion Time Zones time_zone_name } (*typedef struct _REG_TZI_FORMAT { LONG Bias; LONG StandardBias; LONG DaylightBias; SYSTEMTIME StandardDate; SYSTEMTIME DaylightDate; } REG_TZI_FORMAT; *) type TSystemTime2 = record wYear: Word; wMonth: Word; wDayOfWeek: Word; wDay: Word; wHour: Word; wMinute: Word; wSecond: Word; wMilliseconds: Word; end; type //PTimeZoneInformation = ^TTimeZoneInformation; _TIME_ZONE_INFORMATION2 = record Bias: Longint; StandardName: array[0..31] of CHAR; StandardDate: TSystemTime2; StandardBias: Longint; DaylightName: array[0..31] of CHAR; DaylightDate: TSystemTime2; DaylightBias: Longint; end; //{$EXTERNALSYM _TIME_ZONE_INFORMATION} TTimeZoneInformation2 = _TIME_ZONE_INFORMATION2; //TIME_ZONE_INFORMATION = _TIME_ZONE_INFORMATION; function GetTimeZoneInformation2(var lpTimeZoneInfo: TTimeZoneInformation2): DWORD; external 'GetTimeZoneInformation@kernel32.dll stdcall'; function GetDynamicTimeZoneInformation2(var lpTimeZoneInfo: TTimeZoneInformation2): DWORD; external 'GetDynamicTimeZoneInformation@kernel32.dll stdcall'; function MyGetTickCountX: Longint; external 'GetTickCount@kernel32.dll stdcall'; // function GetTimeZoneInformation(var lpTimeZoneInformation: TTimeZoneInformation): DWORD; stdcall; //6. TimeZones function GetXRTLGetTimeZones: TXRTLTimeZones; forward; var i: integer; S: AnsiString; A: TDateTime; bigfloat: extended; byt: TBytes; function StrToBytes2(const Value: String): TBytes; var i: integer; begin SetLength(result, Length(Value)); for i:= 0 to Length(Value)-1 do result[i]:= Ord(Value[i+1])- 48; //-48 end; function BytesToStr2(const Value: TBytes): String; var I: integer; Letra: char; begin result:= ''; for I:= Length(Value)-1 Downto 0 do begin letra:= Chr(Value[I] + 48); result:= letra + result; end; end; function IntToRoman2(Value: Longint): string; begin writeln(IntToRoman(Value)); end; procedure LeibnizFormula; var zeta, bigdecadd: double; tac: boolean; begin zeta:= 0; tac:= true; for i:= 1 to 50000 do if NOT (i mod 2 = 0) then begin tac:= not tac; if tac then zeta:= zeta - 1/i else zeta:= zeta + 1/i; end; writeln('harmonic alternate leibniz formula to PI/4: '+floatToStr(zeta)) writeln(floatToStr(maxcalc('PI/4'))) writeln(floatToStr(PIOn4)) end; function GetXRTLGetTimeZones: TXRTLTimeZones; var mzone: TXRTLTimeZones; i: integer; begin {mzone:= TXRTLTimeZones.Create; //not cause of interface func mzone:= XRTLGetTimeZones; for i:= 1 to mzone.Count-1 do writeln(mzone.item[i].display); } //mzone.Free; end; procedure TXRTLTimeZones_Refresh; var osV: TOSVERSIONINFO; TimeZonesKey: string; KeyNames: TStringList; Registry: TRegistry; i: Integer; FItems: TStringlist; //TObjectlist; aTimeZone: TXRTLTimeZone; FIndex: DWORD; Rtzi: REGTIMEZONEINFORMATION; begin //FItems.Clear; osV.dwOSVersionInfoSize:= SizeOf(osV); GetVersionEx(osV); if osV.dwPlatformId = VER_PLATFORM_WIN32_NT then TimeZonesKey:= SKEY_NT else TimeZonesKey:= SKEY_9X; Registry:= Nil; KeyNames:= Nil; try Registry:= TRegistry.Create; Registry.RootKey:= HKEY_LOCAL_MACHINE; if not Registry.OpenKeyReadOnly(TimeZonesKey) then Exit; KeyNames:= TStringList.Create; Registry.GetKeyNames(KeyNames); for i:= 0 to KeyNames.Count - 1 do begin if not Registry.OpenKeyReadOnly(TimeZonesKey + KeyNames[i]) then Continue; //with fitems do begin //add(Registry.ReadBinaryData('TZI', RTZI, SizeOf(RTZI))); { atimezone.Display:= Registry.ReadString('Display'); atimezone.Daylight:= Registry.ReadString('Dlt'); atimezone.Standard:= Registry.ReadString('Std'); } //Registry.ReadBinaryData('TZI', RTZI, SizeOf(RTZI)) writeln(Registry.ReadString('Display')+' --->'); writeln(Registry.ReadString('Dlt') + ' : '+Registry.ReadString('Std')); writeln(' '); {if TimeZonesKey = SKEY_NT then FIndex:= Registry.ReadInteger('Index') else FIndex:= Count - 1; } //end; end; //fitems.Sort; finally Registry.CloseKey; Registry.Free; Registry:= NIL; KeyNames.Free; KeyNames:= NIL; //FreeAndNil(Registry); //FreeAndNil(KeyNames); end; end; function BytesToHex(aSource: TBytes): string; var oldate: word; newdate: TStDate; begin SetLength(Result, Length(aSource) * 2); if Length(aSource) > 0 then //BinToHex(aSource[0], PChar(Result), Length(aSource)); //result:= BinToHex2(aSource); newdate:= Convert2ByteDate(oldate) end; function FileTimeToDateTime2(FileTime: TFileTime): TDateTime; var ModifiedTime: TFileTime; SystemTime: TSystemTime; begin Result := 0; if (FileTime.dwLowDateTime = 0) and (FileTime.dwHighDateTime = 0) then Exit; try FileTimeToLocalFileTime(FileTime, ModifiedTime); FileTimeToSystemTime(ModifiedTime, SystemTime); Result := SystemTimeToDateTime(SystemTime); except Result := Now; // Something to return in case of error writeln('error in filetimetodatetime2') end; end; function DateTimeToFileTime2(FileTime: TDateTime): TFileTime; var LocalFileTime, Ft: TFileTime; SystemTime: TSystemTime; begin Result.dwLowDateTime := 0; Result.dwHighDateTime := 0; DateTimeToSystemTime(FileTime, SystemTime); SystemTimeToFileTime(SystemTime, LocalFileTime); LocalFileTimeToFileTime(LocalFileTime, Ft); Result := Ft; end; procedure letFloatingFormatflowTest; var float : extended; begin // Set up our floating point number float := 1234.567; // Display a sample value using all of the format options // Round out the decimal value Writeln('##### : '+FormatFloat('#####', float)); Writeln('00000 : '+FormatFloat('00000', float)); Writeln('0 : '+FormatFloat('0' , float)); Writeln('#,##0 : '+FormatFloat('#,##0', float)); Writeln(',0 : '+FormatFloat(',0' , float)); Writeln(''); // Include the decimal value Writeln('0.#### : '+FormatFloat('0.####', float)); Writeln('0.0000 : '+FormatFloat('0.0000', float)); Writeln(''); // Scientific format Writeln('0.0000000E+00 : '+FormatFloat('0.0000000E+00', float)); Writeln('0.0000000E-00 : '+FormatFloat('0.0000000E-00', float)); Writeln('#.#######E-## : '+FormatFloat('#.#######E-##', float)); Writeln(''); // Include freeform text Writeln('"Value = "0.0 : '+FormatFloat('"Value = "0.0', float)); Writeln(''); // Different formatting for negative numbers Writeln('0.0 : '+FormatFloat('0.0' , -1234.567)); Writeln('0.0 "CR";0.0 "DB" : '+ FormatFloat('0.0 "CR";0.0 "DB"', -1234.567)); Writeln('0.0 "CR";0.0 "DB" : '+ FormatFloat('0.0 "CR";0.0 "DB"', 1234.567)); Writeln(''); // Different format for zero value Writeln('0.0 : '+FormatFloat('0.0' , 0.0)); Writeln('0.0;-0.0;"Nothing" : '+ FormatFloat('0.0;-0.0;"Nothing"', 0.0)); end; {$IFNDEF VERSION4} const aTIME_ZONE_ID_INVALID = $FFFFFFFF; aTIME_ZONE_ID_UNKNOWN = 0; aTIME_ZONE_ID_STANDARD = 1; aTIME_ZONE_ID_DAYLIGHT = 2; {$ENDIF} type LHFlags = array[0..167] of Boolean; TLHData = array[0..6{TStDayType}] of array[0..2] of Byte; //const BitFlags = array[0..7] of byte; // = ($01, $02, $04, $08, $10, $20, $40, $80); procedure TStNetUserItem_SetLogonHours(LogonHours: TDatetime {TStNetUserLogonTimes}); var Data : TLHData; GMTOffset : Integer; BitOffset : Integer; DayOfWeek : Integer; HourOfDay : Integer; TZ : TTimeZoneInformation; USER_INFO : integer; {TUSER_INFO_1020;} ErrorD : DWord; ParmErr : DWord; //const //BitFlags : array[0..7] of byte = ($01, $02, $04, $08, $10, $20, $40, $80); begin //if (FUserData = nil) then //Refresh; case GetTimeZoneInformation(TZ) of TIME_ZONE_ID_UNKNOWN : GMTOffset := TZ.Bias div MinutesInHour; TIME_ZONE_ID_STANDARD: GMTOffset := (TZ.Bias + TZ.StandardBias) div MinutesInHour; TIME_ZONE_ID_DAYLIGHT: GMTOffset := (TZ.Bias + TZ.DaylightBias) div MinutesInHour; else GMTOffset := 0; end; { Default to ALL hours for logon } // FillChar2(Data, SizeOf(Data), 255); { Populate the logon hours structure with correct information } //for DayOfWeek := Ord(Sunday) to Ord(Saturday) do begin for HourOfDay := 0 to HoursInDay-1 do begin { Get the correct offset into the array of booleans } BitOffset := -(GMTOffset) + ((DayOfWeek * HoursInDay) + HourOfDay); if BitOffset > 168 then Dec1(BitOffset, 168) else if BitOffset < 1 then Inc1(BitOffset, 168); { just set the True logon hours (already set to False) } {if not LHFlags(LogonHours)[BitOffset-1] then ClearByteFlag(Data[TStDayType(DayOfWeek)][HourOfDay div 8], BitFlags[HourOfDay mod 8]); end;} end; { Update the server with the new logon hours } {USER_INFO.usri1020_logon_hours := @Data; USER_INFO.usri1020_units_per_week := UNITS_PER_WEEK; ErrorD := StNetUserSetInfo(FServer, FName, 1020, @USER_INFO, ParmErr); if ErrorD = NERR_SUCCESS then begin TUSER_INFO_3(FUserData^).usri3_logon_hours := @Data; end else begin RaiseStWin32Error(EStNetException, ErrorD); end; } end; type NET_API_STATUS = Integer; type ENetRemoteTODError = Exception; const NERR_Success = 0; //public const Int32 ERROR_INSUFFICIENT_BUFFER = 122; ERROR_INSUFFICIENT_BUFFER = 122; procedure NetCheck(ErrCode: NET_API_STATUS); begin if ErrCode <> NERR_Success then begin case ErrCode of ERROR_ACCESS_DENIED: begin raise; ENetRemoteTODError.Create('Access is Denied'); end; //ERROR_INVALID_OWNER: //raise ENetRemoteTODError.Create('Cannot assign the owner of this //object.'); ERROR_INSUFFICIENT_BUFFER: ENetRemoteTODError.Create('Buffer passed was too small'); else begin raise; Exception.Create('Error Code: ' + IntToStr(ErrCode) + #13 + SysErrorMessage(ErrCode)); end end; end; end; function GetNthDSTDOW(Y,M,DST_DOW,N:word):integer; {For Year "Y" and Month "M" and DayOfWeek "DST_DOW", return the day of month for "DST_DOW" number "N"} {If N is larger than the number of DST_DOW's in the month, return the day of the last one} {If Y, M, or N are otherwise invalid, return 0} var dt:TDateTime; NdayDom, maxdays:integer; begin if TryEncodeDate(y,m,1,dt) and (n>0) then {get date of first of month} begin //writeln(datetimetostr(dt)) if n>5 then n:=5; NdayDOM:=8+DST_DOW-DayOfTheWeek(dt); {1st DST_DOW Day of Month} result:=NdayDOM+7*(n-1); maxdays:=JdaysinMonth(dt); If result>maxdays then repeat dec1(Result,7) until Result<=Maxdays; end else result:=0; end; procedure TimeZone_FormActivate(Sender: TObject); var timezoneinfo2: TTimezoneinformation2; timezoneinfo: _TIME_ZONE_INFORMATION; r:word; t:TDatetime; y,m,d,d2:word; tzo: TXRTLTimeZones; aTimeZone: TXRTLTimeZone; tzi: REGTIMEZONEINFORMATION; begin //memo1.clear; //SetTimeZoneInformation //setlength(timezoneinfo2.StandardName,40) //tzo:= XRTLGetTimeZones; -->Failed to get data for 'Index'. writeln('string Bias '+itoa(RFCTimeZoneToGMTBias('W. Europe Standard Time'))) writeln('string Bias '+itoa(RFCTimeZoneToGMTBias('UT'))) {function GMTBias: Integer; function GMTTimeToLocalTime(const D: TDateTime): TDateTime; function LocalTimeToGMTTime(const D: TDateTime): TDateTime; function NowAsGMTTime: TDateTime; } writeln('time zone bias: '+itoa(GMTBias)) writeln(datetimetoStr(GMTTimeToLocalTime(now))); writeln(datetimetostr(LocalTimeToGMTTime(now))); writeln(datetimetostr(NowAsGMTTime)); writeln(''); atimezone:= TXRTLTimeZone.create; writeln(datetimetostr(XRTLDateTimeToTimeZoneTime(now,atimezone))) writeln('time zone display: '+atimezone.display) writeln('time zone daylight: '+atimezone.daylight) writeln('time zone standard: '+atimezone.standard) tzi:= atimezone.RTZI; writeln('time zone bias: '+itoa(tzi.bias)) //writeln('time zone bias: '+datetimetostr(SystemTimeToDateTime((tzi.standarddate)))) atimezone.Free; //GetDynamicTimezoneInformation decodedate(now,y,m,d); {need year later on just for formatting convenience} r:= GetTimezoneInformation2(timezoneinfo2); if r>=0 then with timezoneinfo2 do begin daylightdate.wYear:=y; writeln('SYSTEM TIME ZONE INFORMATION'); writeln('time zone: '+timezone) writeln('time zone bias: '+itoa(iptimezonebias)) writeln('time zone bias time: '+timetoStr(timezonebias)) writeln(''); writeln('Current Bias from local to UTC: '+inttostr(bias)+' minutes'); writeln('Current Standard Bias to UTC: '+inttostr(standardbias)+' minutes'); writeln('Current Dailight Bias to UTC: '+inttostr(daylightbias)+' minutes'); writeln(' (UTC = Local time + Bias)'); //setarraylength(timezoneinfo2.StandardName,40) writeln('Time zone name: '+ standardname[0]); // writeln('Time zone name: '+ standardname[1]); {for it:= 0 to length(standardname)-1 do sr:= sr + standardname[it]; writeln('Time zone name: '+ sr); } writeln(itoa(Year(now))) writeln(itoa(month(now))) with daylightdate do begin{dayLight saving start date} {Field wDayOfWeek field contains weekday of start (0=Sunday)} {Day of month Field speciies which occurrence of the day of week is the start day} {getNthDSTDOW function takes this information and converts it into day of month} writeln('wyear set '+itoa(daylightdate.wyear)) writeln('wmonth set '+itoa(daylightdate.wmonth)) writeln('wdayofweek '+itoa(daylightdate.wdayofweek)) writeln('whour '+itoa(daylightdate.whour)) writeln('wminute '+itoa(daylightdate.wminute)) writeln('wday '+itoa(wday)) d2:= getNthDSTDOW(y,wmonth,wDayOfWeek,wDay); writeln('d2 '+itoa(d2)) //t:=encodedate(y,2,4)+encodetime(2,3,4,1); try t:=encodedate(y,wmonth,d2)+encodetime(whour,wminute,wsecond,1); except writeln('Exception: Invalid argument to date encode.'); end; end; writeln(formatdatetime('"Daylight savings starts: " mmmm dd hh:nn am/pm',t)); with standarddate do {daylight saving end date} begin {same computation as for start time} d2:=getNthDSTDOW(y,wmonth,wDayOfWeek,wday); try t:=encodedate(y,wmonth,d2)+encodetime(whour,wminute,wsecond,wmilliseconds); except writeln('Exception: Invalid argument to date encode.'); //raiselastexception; end; end; writeln(formatdatetime('"Daylight savings ends: " mmmm dd hh:nn am/pm',t)); //writeln('Daylight savings name: '+Daylightname); writeln('Daylight savings bias: '+inttostr(Daylightbias)+' minutes'); writeln(''); case r of time_zone_Id_unknown: writeln('Current daylight status is unknown'); time_zone_id_standard:writeln('We are not currently in daylight savings time period!'); time_zone_id_daylight: writeln('We are currently in the daylight savings time period'); end; end else writeln('Time zone information retrieval failed'); end; {SYSTEM TIME ZONE INFORMATION Current Bias from local to UTC: -60 minutes (UTC = Local time + Bias) Time zone name: W. Europe Standard Time Daylight savings starts: March 29 02:00 am Daylight savings ends: October 25 03:00 am Daylight savings name: W. Europe Summer Time Daylight savings bias: -60 minutes We are not currently in the daylight savings time period } var myst: TStringGrid; k,t: integer; st, lt: TSystemTime; //d: decimal; BEGIN //Main // ShowMessage(ReplaceRegExpr('World','Hello, EKON TRex Time Travel Superfunction Tester World!', 'Earth',true)); myst:= TStringGrid.create(self) myst.rowcount:= 10; myst.colcount:= 10; for k:= 1 to 40 do begin myst.Cells[k ,0]:= inttoStr(k); myst.Cells[0,(k div 4)]:= inttoStr(k+1);//-47); end; for k:= 1 to myst.ColCount - 1 do for t:= 1 to myst.RowCount - 1 do myst.Cells[k ,t]:= inttoStr(t); //myst.Cells[0,t]:= inttoStr(t+1);//-47); myst.Free; IntToRoman2(2012); IntToRoman2(2015); printF('addition theorem %.18f ',[maxcalc('sin(2.5/2)')]) printF('addition theorem %.18f ',[maxcalc('sqrt(1/2*(1-cos(2.5)))')]) printF('addition theorem2 %22.18f ',[maxcalc('cos(2.5/2)')]) printF('addition theorem2 %22.18f ',[maxcalc('sqrt(1/2*(1+cos(2.5)))')]) bigfloat:= maXcalc('ln(1.0000*10^4932)/ln(2)'); printF('limes extended %22.18f ',[bigfloat]) printF('limes extended int return %.18f ',[maXcalc('2^16383.749363984471100000')]) writeln(formatBigInt(powerBig(10,22))) writeln(formatBigInt(powerBig(9,2222))) LeibnizFormula; GetXRTLGetTimeZones; printF('max extended %.18f',[bigfloat]); writeln('MaxFloatingPoint: '+floatToStr(MaxFloatingPoint)); //StrtoBytes byt:= StrToBytes('DevMediaBox'); for I:= 0 to Length(byt) - 1 do write(IntToStr(byt[I])+' '); writeln(BytestoStr(byt)); writeln(''); byt:= StrToBytes2('DevMediaBox'); //internal test for I:= 0 to Length(byt) - 1 do write(IntToStr(byt[I])+' '); writeln(BytestoStr2(byt)); it:= 6; SelftestPEM; SelfTestCFundamentUtils; SelfTestCFileUtils; try SelfTestCDateTime; except writeln('Except : SelfTestCDateTime;') dec(it) end; SelfTestCTimer; SelfTestCRandom; Writeln(itoa(it)+' Units Tested with success ') ShowMessageBig(itoa(it)+' Units Tested with success!'); Assert2(FilePath('C', '..\X\Y', 'A\B', '\') = 'A\X\Y\C', 'FilePath'); Assert2(PathCanonical('\A\B\..\C\D\..\..\..\..\', '\') = '\', 'PathCanonical'); Assert2(UnixPathToWinPath('/c/d.f') = '\c\d.f', 'UnixPathToWinPath'); Assert2(WinPathToUnixPath('\c\d.f') = '/c/d.f', 'WinPathToUnixPath'); A:= EncodeDateTime(2001, 09, 02, 12, 11, 10, 0); Assert2(Month(A) = 9, 'EncodeDateTime'); S:= GMTTimeToRFC1123TimeA(A, True); Assert2(S = '12:11:10 GMT','GMT'); S:= GMTDateTimeToRFC1123DateTimeA(A, True); Assert2(S = 'Sun, 02 Sep 2001 12:11:10 GMT', 'GMTDateTimeToRFC1123DateTime'); Assert2(TickDeltaW($FFFFFFF6, 0) = 10,'TrickDelta'); Assert2(CPUClockFrequency > 0,'RTC Prepare'); Assert2(Length(RandomPassword(0, 0, True, True, True)) = 0,'random passwd'); Assert2(Length(RandomPassword(1, 1, True, True, True)) = 1,'random passwd'); CompareDateTime(DateOf(Now),DateOf(Now)+1) printF('sin test in RAD %.18f',[sin((3))]); printF('sinj test in RAD %.18f',[sinj((3))]); printF('sin test in GRAD %.18f',[sin(gradtorad(60))]); //printF('sin test in GRAD %.18f',[radtodeg(sin(60))]); printF('sinj test in GRAD %.18f',[sinj(gradtorad(60))]); printF('sinc test in GRAD %.18f',[sinc(gradtorad(60))]); printF('sin test in DEG %.18f',[Sin(degtorad(60))]); printF('sinj test in DEG %.18f',[sinj(degtorad(60))]); printF('cos test in DEG %.18f',[Cos(degtorad(60))]); printF('cosj test in DEG %.18f',[Cosj(degtorad(60))]); //sin(60)=0.866 --> arcsin(0.866)=59,99999999 printF('ARCSIN test in DEG %.18f',[radtodeg(arcsin(Sin(degtorad(60))))]); printF('ARCSIN test in DEG %.18f',[radtodeg(arcsin(Sinj(degtorad(60))))]); printF('ARCSIN test in DEG %.18f',[radtodeg(stinvSin(Sinj(degtorad(60))))]); //CL.AddDelphiFunction('Function StInvSin( Y : Double) : Double'); printF('ARCCOS test in DEG %.18f',[radtodeg(arccos(Cos(degtorad(60))))]); //printF('sinj test in DEG %.18f',[sinj(degtorad(60))]); printF('sin test not %f',[sin(radtograd(60))]); //InputQuery( const ACaption, APrompt : string; var Value : string) : Boolean writeln(floatToStr(single(PI))) PrintF('floatToStr(less type cast %.18f: ',[PI]) PrintF('floatToStr(cast single(PI) %.18f: ',[single(PI)]) // with Tstringlist.create do begin clear; add('this is my own'); //exchange(1,1) //Destroy; writeln(strings[0]) Free; end; with TStringGrid.Create(self) do begin tabstop; tabstops[true]; free; end; writeln('ST Time> '+currenttimestring('hh:mm:ss tt',false)); writeln('ST DateDay> '+dayofWeektoString(stdayofWeek(currentdate))); TimeZone_FormActivate(self); writeln('back '+DatetimetoStr(FileTimeToDateTime2(DateTimeToFileTime2(inchour(now,-2))))) GetSystemTime(st); GetLocalTime(lt); printF('The system time is: %d: %d', [st.wHour, st.wMinute]); printF('The local time is: %d: %d', [lt.wHour, lt.wMinute]); //letFloatingFormatflowTest; TXRTLTimeZones_Refresh; END. doc: All translations between UTC time and local time are based on the following formula: UTC = local time + bias The bias is the difference, in minutes, between UTC time and local time. ref: using System; public class Example { public static void Main() { DateTime date1 = new DateTime(2010, 3, 14, 2, 30, 00); Console.WriteLine("Invalid Time: {0}", TimeZoneInfo.Local.IsInvalidTime(date1)); long ft = date1.ToFileTime(); DateTime date2 = DateTime.FromFileTime(ft); Console.WriteLine("{0} -> {1}", date1, date2); } } // The example displays the following output: // Invalid Time: True // 3/14/2010 2:30:00 AM -> 3/14/2010 3:30:00 AM #include #include void main() { SYSTEMTIME st, lt; GetSystemTime(&st); GetLocalTime(<); printf("The system time is: %02d:%02d\n", st.wHour, st.wMinute); printf(" The local time is: %02d:%02d\n", lt.wHour, lt.wMinute); } Alternating harmonic series The first fourteen partial sums of the alternating harmonic series (black line segments) shown converging to the natural logarithm of 2 (red line). The series \sum_{n = 1}^\infty \frac{(-1)^{n + 1}}{n} \;=\; 1 \,-\, \frac{1}{2} \,+\, \frac{1}{3} \,-\, \frac{1}{4} \,+\, \frac{1}{5} \,-\, \cdots is known as the alternating harmonic series. This series converges by the alternating series test. In particular, the sum is equal to the natural logarithm of 2: 1 \,-\, \frac{1}{2} \,+\, \frac{1}{3} \,-\, \frac{1}{4} \,+\, \frac{1}{5} \,-\, \cdots \;=\; \ln 2. 1-1/2+1/3-1/4+1/5-1/6... = ln2 This formula is a special case of the Mercator series, the Taylor series for the natural logarithm. A related series can be derived from the Taylor series for the arctangent: \sum_{n = 0}^\infty \frac{(-1)^{n}}{2n+1} \;\;=\;\; 1 \,-\, \frac{1}{3} \,+\, \frac{1}{5} \,-\, \frac{1}{7} \,+\, \cdots \;\;=\;\; \frac{\pi}{4}. This is known as the Leibniz formula for pi. A related series can be derived from the Taylor series for the arctangent: \sum_{n = 0}^\infty \frac{(-1)^{n}}{2n+1} \;\;=\;\; 1 \,-\, \frac{1}{3} \,+\, \frac{1}{5} \,-\, \frac{1}{7} \,+\, \cdots \;\;=\;\; \frac{\pi}{4}. pi/4 This is known as the Leibniz formula for pi. {Delphi} function BytesToHex(aSource: TBytes): string; begin SetLength(Result, Length(aSource) * 2); if Length(aSource) > 0 then BinToHex(aSource[0], PChar(Result), Length(aSource)); end; ----app_template_loaded_code----