delphitimetostring
2005-03-15 22:53
585 查看
Function TimeTToDateTimeStr(TimeT : Integer) : String;
Const UnixDateDelta = 25569; { days between 12/31/1899 and 1/1/1970 }
Var
DT : TDateTime;
TZ : TTimeZoneInformation;
Res : DWord;
Begin
If (TimeT = 0) Then Result := ''
Else Begin
{ Unix TIME_T is secs since 1/1/1970 }
DT := UnixDateDelta+(TimeT / (24*60*60)); { in UTC }
{ calculate bias }
Res := GetTimeZoneInformation(TZ);
If (Res = TIME_ZONE_ID_INVALID) Then RaiseLastWin32Error;
If (Res = TIME_ZONE_ID_STANDARD) Then Begin
DT := DT-((TZ.Bias+TZ.StandardBias) / (24*60));
Result := DateTimeToStr(DT)+' '+WideCharToString(TZ.StandardName);
End
Else Begin { daylight saving time }
DT := DT-((TZ.Bias+TZ.DaylightBias) / (24*60));
Result := DateTimeToStr(DT)+' '+WideCharToString(TZ.DaylightName);
End;
End;
End;
Const UnixDateDelta = 25569; { days between 12/31/1899 and 1/1/1970 }
Var
DT : TDateTime;
TZ : TTimeZoneInformation;
Res : DWord;
Begin
If (TimeT = 0) Then Result := ''
Else Begin
{ Unix TIME_T is secs since 1/1/1970 }
DT := UnixDateDelta+(TimeT / (24*60*60)); { in UTC }
{ calculate bias }
Res := GetTimeZoneInformation(TZ);
If (Res = TIME_ZONE_ID_INVALID) Then RaiseLastWin32Error;
If (Res = TIME_ZONE_ID_STANDARD) Then Begin
DT := DT-((TZ.Bias+TZ.StandardBias) / (24*60));
Result := DateTimeToStr(DT)+' '+WideCharToString(TZ.StandardName);
End
Else Begin { daylight saving time }
DT := DT-((TZ.Bias+TZ.DaylightBias) / (24*60));
Result := DateTimeToStr(DT)+' '+WideCharToString(TZ.DaylightName);
End;
End;
End;
相关文章推荐
- time value from 1970 to date string.
- leetcode day6 -- String to Integer (atoi) && Best Time to Buy and Sell Stock I II III
- System.DataTime.Now.TOstring() 的各种格式
- [C++] Running time and Integer to String
- Date 的 toLocaleTimeString() 格式问题
- Delphi数据类型转换(有几个字符串函数没见过,比如StringToWideChar和WideCharToString)
- DataTime.ToString 的方法。
- DataTime.ToString("xx") 转换
- ISO 8601: Delphi way to convert XML date and time to TDateTime and back (via: Stack Overflow)
- 诡异的DataTime.Now.ToString()
- symbian string to TTime
- System.DataTime.Now.ToString()的各种格式
- 关于DataTime的问题 对比ToShortDateString()和ToString("yyyy-MM-dd")
- SQL string to date time
- DataTime or ToString用法
- golang Time to String
- 简介JavaScript中toTimeString()方法的使用
- 简介JavaScript中toTimeString()方法的使用
- stringToTime && timeToString
- How to read a whole document content into a string one-time