### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: [Solve] Date GMT conversion  (Read 1725 times)

#### cappe

• Full Member
• Posts: 167
##### [Solve] Date GMT conversion
« on: October 11, 2021, 05:25:49 pm »
How do I convert this "Thu Oct 14 2021 00:00:00 GMT+0200 (Ora legale dell’Europa centrale)//" date to tdatetime?
« Last Edit: October 15, 2021, 09:31:45 am by cappe »

#### sstvmaster

• Sr. Member
• Posts: 267
##### Re: Date GMT conversion
« Reply #1 on: October 11, 2021, 10:00:06 pm »
I think so:
Code: Pascal  [Select][+][-]
1. ...
2. uses DateUtils;
3. ...
4. procedure TForm1.Button1Click(Sender: TObject);
5. const
6.   SDN : TWeekNameArray = ('Sun','Mon','Tue','Wen','Thu','Fri','Sat');
7.   SMN : TMonthNameArray = ('Jan','Feb','Mar','Apr','May','Jun',
8.                            'Jul','Aug','Sep','Oct','Nov','Dec');
9. var
10.   dt: TDateTime;
11.   fs: TFormatSettings;
12. begin
13.   fs := DefaultFormatSettings;
14.   fs.ShortMonthNames := SMN;
15.   fs.ShortDayNames   := SDN;
16.   dt := ScanDateTime('DDD mmm d yyyy hh:nn:ss','Mon Oct 11 2021 21:54:00 GMT+0200', fs);
17.
18.   // test only
19.   ShowMessage( FormatDateTime('dd.mm.yyyy hh:nn:ss', dt) );
20. end;
21.

If you are in german speaking country SDN and SMN must set to english words.
Windows 10
Lazarus: 2.0.12 and trunk (main)

#### marcov

• Hero Member
• Posts: 9768
• FPC developer.
##### Re: Date GMT conversion
« Reply #2 on: October 11, 2021, 10:06:31 pm »

On Windows you can get fs for a given language directly, e.g.

Code: Pascal  [Select][+][-]
1.
2.
3. uses sysutils;
4.
5. const LCID_English = 2057; // british
6.
7. begin
8.    GetLocaleFormatSettings(LCID_English,fs);
9.   dt:= .... scandatetime...
10. end;
11.