hidrau
asked on
Working with formatDateTime - doubt
Hello guys
I am creating a xml that has a field that requires a format this way: '20111107T15:01:04-03:00'
The documentation tells:
A combination Date and Time. Note the presence of a “T” character between the date and time portions, and the use of colons to separate hours, minutes, and seconds.
// These are as per ISO 8601.Datetime Format: YYYYMMDDTHH:MM:SS[[+-]HH:M M]? (the first MM is Datetime Format: YYYYMMDDTHH:MM:SS[[+-]HH:M M]
for date and time it is ok for me. But I didn't understand this part [[+-]HH:MM]
what is it?
thanks
I am creating a xml that has a field that requires a format this way: '20111107T15:01:04-03:00'
The documentation tells:
A combination Date and Time. Note the presence of a “T” character between the date and time portions, and the use of colons to separate hours, minutes, and seconds.
// These are as per ISO 8601.Datetime Format: YYYYMMDDTHH:MM:SS[[+-]HH:M
for date and time it is ok for me. But I didn't understand this part [[+-]HH:MM]
what is it?
thanks
ASKER
ok, I got it.
how can I assemble that formating?
how can I assemble that formating?
You can assemble formatting like the example you already have on your code:
'20111107T15:01:04-03:00' where -03:00 is the UTC (Greenland, Uruguay, Suriname countries)
Then if you need to change to another country, you can take a look on this chart:
http://en.wikipedia.org/wiki/List_of_time_zones_by_country
'20111107T15:01:04-03:00' where -03:00 is the UTC (Greenland, Uruguay, Suriname countries)
Then if you need to change to another country, you can take a look on this chart:
http://en.wikipedia.org/wiki/List_of_time_zones_by_country
ASKER
hummmm
this way:
EDIT1.Text := FormatDateTime('YYYYMMDD', NOW) + 'T' + FormatDateTime('HH:MM:SS', NOW) + FormatDateTime('[[+-]HH:MM ]',now)
the result is not what I expect
take a look at: 20111108T17:20:21[[+-]17:2 0]
if you could give me an example
this way:
EDIT1.Text := FormatDateTime('YYYYMMDD',
the result is not what I expect
take a look at: 20111108T17:20:21[[+-]17:2
if you could give me an example
The FormatDateTime can't get the timezone instead use the GetTimeZoneInformation():
procedure TForm1.Button1Click(Sender : TObject);
var
MyTime : TDateTime;
UTC: TSystemTime;
TimeZoneInfo:TIME_ZONE_INF ORMATION;
bias : Double;
begin
GetTimeZoneInformation(Tim eZoneInfo) ;
bias := TimeZoneInfo.bias/60;
with Memo1.Lines do
begin
Add(FloatToStr(bias));
end;
end;
procedure TForm1.Button1Click(Sender
var
MyTime : TDateTime;
UTC: TSystemTime;
TimeZoneInfo:TIME_ZONE_INF
bias : Double;
begin
GetTimeZoneInformation(Tim
bias := TimeZoneInfo.bias/60;
with Memo1.Lines do
begin
Add(FloatToStr(bias));
end;
end;
ASKER
armchang:
ok, I had a value 3 as result.
But how can I reach this? '20111107T15:01:04-03:00'
ok, I had a value 3 as result.
But how can I reach this? '20111107T15:01:04-03:00'
Tried and tested, working but I need to post the unit file as there are needed functions:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
function rightString(ctext : string; nlen: integer) : string ;
function RTrim(ctext: string) : string;
function LTrim(ctext: string) : string;
function PadL(ctext : string; nlen:integer ; cchar : char) : string ;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.PadL(ctext : string; nlen:integer ; cchar : char) : string ;
var
creturn : string ;
ntemp : integer ;
nmax : integer ;
begin
creturn := LTrim(RTrim(ctext));
nmax := nlen ;
dec(nmax,length(creturn)) ;
if nmax > 0 then
begin
for ntemp := 1 to nmax do
creturn := concat(cchar,creturn) ;
result := creturn ;
end
else
result := rightString(creturn,nlen) ;
end;
function TForm1.rightString(ctext : string; nlen: integer) : string ;
var
ntemp : word ;
begin
result := ctext ;
if (length(ctext) > nlen) then
begin
ntemp := (length(ctext)-nlen)+1 ;
result := copy(ctext,ntemp,nlen) ;
end;
end;
{ Right Trim }
function TForm1.RTrim(ctext: string) : string;
var
nloop : integer ;
begin
if (length(ctext) > 0) then
begin
for nloop := length(ctext) downto 1 do begin
if (not (ord(ctext[nloop]) in [0,1,2,32])) then
begin
ctext := copy(ctext,1,nloop) ;
break ;
end;
end;
end;
result := ctext ;
end;
function TForm1.LTrim(ctext: string) : string;
var
nloop : integer ;
ctemp : string ;
begin
ctemp := '' ;
if (length(ctext) > 0) then
begin
for nloop := 1 to length(ctext) do begin
if (ord(ctext[nloop]) <> 32) then
begin
ctemp := ctemp + copy(ctext,nloop,length(ctext)) ;
break ;
end;
end;
end;
result := ctemp ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
MyTime : TDateTime;
UTC: TSystemTime;
TimeZoneInfo:TIME_ZONE_INFORMATION;
bias : Double;
sFinal : string;
begin
Edit1.Text := FormatDateTime('YYYYMMDD', NOW) + 'T' + FormatDateTime('HH:MM:SS', NOW);
GetTimeZoneInformation(TimeZoneInfo);
if (TimeZoneInfo.Bias > 0) then
sFinal := '+' + PadL(IntToStr(TimeZoneInfo.bias div 60), 2, '0') + ':' + PadL(IntToStr(Abs(TimeZoneInfo.bias mod 60)), 2,'0')
else
sFinal := '-' + PadL(IntToStr(Abs(TimeZoneInfo.bias div 60)), 2, '0') + ':' + PadL(IntToStr(Abs(TimeZoneInfo.bias mod 60)), 2, '0');
Edit1.Text := Edit1.Text + sFinal;
end;
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thanks very much friend
For example:
The offset from UTC changes with daylight saving time, e.g. a time offset in Chicago, would be "-06:00" for the winter (Central Standard Time) and "-05:00" for the summer (Central Daylight Time).