您的位置:首页 > 其它

如何格式化日期和时间

2009-11-07 09:31 363 查看
[Setup]
AppName=DateFormat
AppVerName=DateFormat
Uninstallable=false
UpdateUninstallLogAppName=false
DisableDirPage=true
DisableProgramGroupPage=true
DefaultDirName={pf}\DateFormat
DisableStartupPrompt=true

[Code]
#include "LangLib.iss"
type
TSystemTime = record
wYear : Word;
wMonth : Word;
wDayOfWeek : Word;
wDay : Word;
wHour : Word;
wMinute : Word;
wSecond : Word;
wMilliseconds : Word;
end;

procedure GetLocalTime(var lpSystemTime: TSystemTime); external
'GetLocalTime@kernel32.dll';
function GetDateFormat(Locale: Integer;dwFlags: LongInt;
var lpDate: TSystemTime; lpFormat: PChar; lpDateStr: String;
cchDate: Integer): Integer; external
'GetDateFormatA@kernel32.dll';
function GetTimeFormat(Locale: Integer;dwFlags: LongInt;
var lpTime: TSystemTime;lpFormat: PChar;lpTimeStr: String;
cchDate: Integer): Integer; external
'GetTimeFormatA@kernel32.dll';
function GetlastError(): Integer; external
'GetLastError@kernel32.dll';
var
lt : TSystemTime;

function InitializeSetup: Boolean;
begin
// Initialize Lanuage variables
InitLang;
GetLocalTime(lt);
Result := true;
end;
procedure AddDateTime( list: TlistBox; desc: String; lc: LCID );
var
datestring, timestring : String;
begin
list.Items.Add( desc + ' = ' + IntToStr( lc ) );
datestring := StringOfChar(' ',64);
GetDateFormat(lc, DATE_LONGDATE,lt, '' ,datestring,63);
datestring := CastIntegerToString( CastStringToInteger(datestring) );
list.Items.Add( ' Date = ' + datestring );
timestring := StringOfChar(' ',64);
GetTimeFormat(lc, 0, lt , '', timestring,63);
timestring := CastIntegerToString( CastStringToInteger(timestring) );
list.Items.Add( ' Time = ' + timestring );
end;
function DateTimeFormats( BackClicked: Boolean): Boolean;
var
MyList : TListBox;
Next: Boolean;
mylcid :LCID;
datestring, timestring, format: string;
begin
// First open the custom wizard page
ScriptDlgPageOpen();
// Set some captions
ScriptDlgPageSetCaption('Date Time Formats');
ScriptDlgPageSetSubCaption1('List of date and time formats');

MyList := TListBox.Create(WizardForm.ScriptDlgPanel);
MyList.Top := 8;
MyList.Width := WizardForm.ScriptDlgPanel.Width;
MyList.Parent := WizardForm.ScriptDlgPanel;
MyList.Height := WizardForm.ScriptDlgPanel.Height - 24;
AddDateTime( MyList, 'User Default LCID ', GetUserDefaultLCID );
AddDateTime( MyList, 'Systemt Default LCID ', GetSystemDefaultLCID );
mylcid := MakeLCID(MakeLangId(LANG_ITALIAN, SUBLANG_ITALIAN), SORT_DEFAULT);
AddDateTime( MyList, 'Italian LCID ', mylcid );
mylcid := MakeLCID(MakeLangId(LANG_SPANISH, SUBLANG_SPANISH_PUERTO_RICO), SORT_DEFAULT);
AddDateTime( MyList, 'Spanish (Puerto Rico) LCID ', mylcid );
mylcid := MakeLCID(MakeLangId(LANG_ENGLISH, SUBLANG_ENGLISH_EIRE), SORT_DEFAULT);
AddDateTime( MyList, 'English (Irish) LCID ', mylcid );
datestring := StringOfChar(' ',64);
format := 'dd dddd MMMM yyyy';
GetDateFormat(GetUserDefaultLCID,0,lt,format,datestring,63);
datestring := CastIntegerToString( CastStringToInteger(datestring) );
MyList.Items.Add( 'Custom format <' + format + '> = ' + datestring );

timestring := StringOfChar(' ',64);
format := 'hh''--''mm''--''ss';
GetTimeFormat(GetUserDefaultLCID,0,lt,format,timestring,63);
timestring := CastIntegerToString( CastStringToInteger(timestring) );
MyList.Items.Add( 'Custom format <' + format + '> = ' + timestring );

Next := ScriptDlgPageProcessCustom();
// See NextButtonClick and BackButtonClick: return True if the click should be allowed
if not BackClicked then
Result := Next
else
Result := not Next;
// Close the wizard page. Do a FullRestore only if the click (see above) is not allowed
ScriptDlgPageClose(not Result);
end;

function ScriptDlgPages(CurPage: Integer; BackClicked: Boolean): Boolean;
begin
if (not BackClicked and (CurPage = wpWelcome)) or (BackClicked and (CurPage = wpReady)) then begin
Result := DateTimeFormats( BackClicked )
end
else
Result := True;
end;
function NextButtonClick(CurPage: Integer): Boolean;
begin
Result := ScriptDlgPages(CurPage, False);
end;
function BackButtonClick(CurPage: Integer): Boolean;
begin
Result := ScriptDlgPages(CurPage, True);
end;本文出自 “学无止境” 博客,请务必保留此出处http://dqk1985.blog.51cto.com/1005868/223421
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: