社区
C++ Builder
帖子详情
如果在TDateTime与time_t以及struct tm之间互相转换?
fancy_zhh
2003-09-29 05:40:35
如果在TDateTime与time_t以及struct tm之间互相转换?
...全文
66
3
打赏
收藏
如果在TDateTime与time_t以及struct tm之间互相转换?
如果在TDateTime与time_t以及struct tm之间互相转换?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
tanbi52
2003-09-29
打赏
举报
回复
不需要转换啊
jingrunx
2003-09-29
打赏
举报
回复
time_t t = DateTimeToUnix(datetime);
struct tm = ???(t);
xizhouhawk
2003-09-29
打赏
举报
回复
TDateTime 与time数据类型一样,不信你赋值试试,只是两个名字而已。
只是作为函数的时候,函数对这两种数据的处理有所不同。
如果你要与自己定义的struct_tm转换,你肯定要将其中的month year day,date提取出来
至于struct_tm里面你要怎么定义都行啊
【Delphi】GMT时间与T
Date
Time
转换
.mht
【Delphi】GMT时间与T
Date
Time
转换
.mht
C++Builder函数库
C++Builder函数库, Date 返回T
Date
Time
对象,包含当前的年月日信息,函数原型如下: System::T
Date
Time
__fastcall Date(void); 2.
Time
返回T
Date
Time
对象,包含当前的时间信息,函数原型如下: System::T
Date
Time
__fastcall
Time
(void); 3. Now 返回T
Date
Time
对象,获取当前的日期和时间信息,函数原型如下: System::T
Date
Time
__fastcall Now(void); 4.
Date
time
ToString 将T
Date
Time
对象
转换
为指定格式的字符串对象,函数原型如下: void __fastcall
Date
Time
ToString(AnsiString &;Result, const AnsiString Format,System: :T
Date
Time
Date
Time
);
T
Date
Time
转UTC的时间差.mht
T
Date
Time
转UTC的时间差.mht
获取时区,根据时区做 UTC时间到本地时间
之间
转换
unit u
Time
ZonesMgr; interface uses Windows, SysUtils, Classes, Registry, DateUtils; type {* 用于读取时区注册表TZI(长度为44)的属性值,存储时区信息 *} PRegTZIInfo = ^TRegTZIInfo; TRegTZIInfo = record Bias: Longint; StandardBias: Longint; DaylightBias: Longint; StandardDate: TSystem
Time
; DaylightDate: TSystem
Time
; end; {* 单个时区管理对象 *} T
Time
Zone = class private F
Time
ZoneName: string; //时区的显示名 FDisplay: string; //夏令时的名字 FDlt: string; //时区标准名字 FStd: string; //是
Time
zone information的缩写,描述时区的一些重要信息 FTZI: PRegTZIInfo; function GetSelf
Time
ZoneInformation: T
Time
ZoneInformation; public con
struct
or Create; de
struct
or Destroy; override; function UTCToLocal
Date
Time
(const AUTC: T
Date
Time
; var ALocal
Date
Time
: T
Date
Time
): Boolean; function Local
Date
Time
ToUTC(const ALocal
Date
Time
: T
Date
Time
; var AUTC: T
Date
Time
): Boolean; public property
Time
ZoneName: string read F
Time
ZoneName write F
Time
ZoneName; property Display: string read FDisplay write FDisplay; property Dlt: string read FDlt write FDlt; property Std: string read FStd write FStd; property TZI: PRegTZIInfo read FTZI write FTZI; end; {* 所有时区管理对象 *} T
Time
Zones = class private F
Time
ZoneKeyPath: string; F
Time
ZoneList: TStringList; FDefault
Time
Zone: T
Time
Zone; procedure Collect
Time
Zone; procedure Destory
Time
Zones; procedure CheckISDefault
Time
Zone(A
Time
Zone: T
Time
Zone); public con
struct
or Create; de
struct
or Destroy; override; function Find
Time
Zone(const ADisplay: string): T
Time
Zone; public property
Time
ZoneList: TStringList read F
Time
ZoneList; property Default
Time
Zone: T
Time
Zone read FDefault
Time
Zone; end; implementation { T
Time
Zones } procedure T
Time
Zones.CheckISDefault
Time
Zone(A
Time
Zone: T
Time
Zone); var Default
Time
Zone: T
Time
ZoneInformation; begin Get
Time
ZoneInformation(Default
Time
Zone); if (A
Time
Zone.TZI.Bias = Default
Time
Zone.Bias) and (A
Time
Zone.Std = Default
Time
Zone.StandardName) then FDefault
Time
Zone := A
Time
Zone; end; procedure T
Time
Zones.Collect
Time
Zone; var reg, tempReg: TRegistry; tempKeyPath: string; temp
Time
ZoneStrings: TStrings; iCir: Integer; temp
Time
Zone: T
Time
Zone; begin reg := TRegistry.Create; try reg.RootKey := HKEY_LOCAL_MACHINE; reg.OpenKey(F
Time
ZoneKeyPath, False); temp
Time
ZoneStrings := TStringList.Create; try reg.GetKeyNames(temp
Time
ZoneStrings); for iCir := 0 to temp
Time
ZoneStrings.Count - 1 do begin tempKeyPath := F
Time
ZoneKeyPath + '\' + temp
Time
ZoneStrings.Strings[iCir]; tempReg := TRegistry.Create; try tempReg.RootKey := HKEY_LOCAL_MACHINE; tempReg.OpenKey(tempKeyPath, False); temp
Time
Zone := T
Time
Zone.Create; temp
Time
Zone.
Time
ZoneName := temp
Time
ZoneStrings.Strings[iCir]; temp
Time
Zone.Display := tempReg.ReadString('Display'); temp
Time
Zone.Std := tempReg.ReadString('Std'); temp
Time
Zone.Dlt := tempReg.ReadString('Dlt'); tempReg.ReadBinaryData('TZI', temp
Time
Zone.TZI^, SizeOf(TRegTZIInfo)); F
Time
ZoneList.AddObject(temp
Time
Zone.Display, temp
Time
Zone); if FDefault
Time
Zone = nil then CheckISDefault
Time
Zone(temp
Time
Zone); finally tempReg.CloseKey; tempReg.Free; end; end; finally temp
Time
ZoneStrings.Free; end; finally reg.CloseKey; reg.Free; end; end; con
struct
or T
Time
Zones.Create; begin F
Time
ZoneKeyPath := '\SOFTWARE\Microsoft\Windows NT\CurrentVersion\
Time
Zones'; F
Time
ZoneList := TStringList.Create; F
Time
ZoneList.Sorted := True; FDefault
Time
Zone := nil; Collect
Time
Zone; end; procedure T
Time
Zones.Destory
Time
Zones; var iCir: Integer; temp
Time
Zone: T
Time
Zone; begin for iCir := 0 to F
Time
ZoneList.Count - 1 do begin temp
Time
Zone := T
Time
Zone(F
Time
ZoneList.Objects[iCir]); temp
Time
Zone.Free; end; F
Time
ZoneList.Clear; F
Time
ZoneList.Free; end; de
struct
or T
Time
Zones.Destroy; begin Destory
Time
Zones(); inherited; end; function T
Time
Zones.Find
Time
Zone(const ADisplay: string): T
Time
Zone; var iIndex: Integer; begin Result := nil; F
Time
ZoneList.Sort; if F
Time
ZoneList.Find(ADisplay, iIndex) then begin Result := T
Time
Zone(F
Time
ZoneList.Objects[iIndex]); end; end; { T
Time
Zone } con
struct
or T
Time
Zone.Create; begin FTZI := Ge
tM
emory(SizeOf(TRegTZIInfo)); FillMemory(FTZI, SizeOf(TRegTZIInfo), 0); end; de
struct
or T
Time
Zone.Destroy; begin FreeMemory(FTZI); inherited; end; function T
Time
Zone.GetSelf
Time
ZoneInformation: T
Time
ZoneInformation; begin Get
Time
ZoneInformation(Result); Result.Bias := TZI^.Bias; Result.StandardBias := TZI^.StandardBias; Result.StandardDate := TZI^.StandardDate; Result.DaylightBias := TZI^.DaylightBias; Result.DaylightDate := TZI^.DaylightDate; end; function T
Time
Zone.Local
Date
Time
ToUTC(const ALocal
Date
Time
: T
Date
Time
; var AUTC: T
Date
Time
): Boolean; var tempLocalToLocal: T
Date
Time
; iMilliSecond: Int64; begin Result := UTCToLocal
Date
Time
(ALocal
Date
Time
, tempLocalToLocal); if Result then begin if tempLocalToLocal > ALocal
Date
Time
then begin iMilliSecond := MilliSecondsBetween(tempLocalToLocal, ALocal
Date
Time
); AUTC := IncMilliSecond(ALocal
Date
Time
, iMilliSecond * -1); end else begin iMilliSecond := MilliSecondsBetween(ALocal
Date
Time
, tempLocalToLocal); AUTC := IncMilliSecond(ALocal
Date
Time
, iMilliSecond); end; Result := True; end; end; function T
Time
Zone.UTCToLocal
Date
Time
(const AUTC: T
Date
Time
; var ALocal
Date
Time
: T
Date
Time
): Boolean; var
Time
Zone: T
Time
ZoneInformation; stUTC, stLC: SYSTEM
TIME
; begin Result := False;
Time
Zone := GetSelf
Time
ZoneInformation;
Date
Time
ToSystem
Time
(AUTC, stUTC); if System
Time
ToTzSpecificLocal
Time
(@
Time
Zone, stUTC, stLC) then begin ALocal
Date
Time
:= System
Time
To
Date
Time
(stLC); Result := True; end; end; end.
Symbian C++ 各种类型
之间
的
转换
.pdf
T
Time
转TBuf、T
Date
Time
转TBuf、TBuf转TInt、TInt转TBuf、TBuf转T
Date
Time
C++ Builder
13,825
社区成员
102,679
社区内容
发帖
与我相关
我的任务
C++ Builder
C++ Builder相关内容讨论区
复制链接
扫一扫
分享
社区描述
C++ Builder相关内容讨论区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章