程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> EncodeDateTime ... TryEncodeDateTime ... 構建時間

EncodeDateTime ... TryEncodeDateTime ... 構建時間

編輯:Delphi

SysUtils.EncodeDateTime
SysUtils.EncodeDate
SysUtils.EncodeTime

DateUtils.EncodeDateDay
DateUtils.EncodeDateMonthWeek
DateUtils.EncodeDateTime
DateUtils.EncodeDateWeek
DateUtils.EncodeDayOfWeekInMonth

DateUtils.TryEncodeDateTime
DateUtils.TryEncodeDateDay
DateUtils.TryEncodeDateWeek
DateUtils.TryEncodeDateMonthWeek
DateUtils.TryEncodeDayOfWeekInMonth

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

type
 TForm1 = class(TForm)
  Memo1: TMemo;
  procedure FormCreate(Sender: TObject);
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

uses DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
var
 t: TDateTime;
 s: string;
begin
 t := EncodeDateTime(2009, 5, 20, 11, 22, 33, 999);
 s := FormatDateTime('yyyy-m-d h:n:s:zzz', t); //2009-5-20 11:22:33:999

 t := EncodeDate(2009, 5, 20);
 s := FormatDateTime('yyyy-m-d h:n:s:zzz', t); //2009-5-20 0:0:0:000

 t := EncodeTime(11, 22, 33, 999);
 s := FormatDateTime('h:n:s:zzz', t);     //11:22:33:999

 t := EncodeDateDay(2009, 140);
 s := FormatDateTime('yyyy-m-d', t);      //2009-5-20

 t := EncodeDateWeek(2009, 21);
 s := FormatDateTime('yyyy-m-d', t);      //2009-5-18
 t := EncodeDateWeek(2009, 21, 3);
 s := FormatDateTime('yyyy-m-d', t);      //2009-5-20

 t := EncodeDateMonthWeek(2009, 5, 3, 3);
 s := FormatDateTime('yyyy-m-d', t);      //2009-5-20

 t := EncodeDayOfWeekInMonth(2009, 5, 3, 3);
 s := FormatDateTime('yyyy-m-d', t);      //2009-5-20

 if TryEncodeDateTime(2009, 5, 20, 11, 22, 33, 999, t) then
  s := FormatDateTime('yyyy-m-d h:n:s:zzz', t);   //2009-5-20 11:22:33:999

 if TryEncodeDateDay(2009, 140, t) then
  s := FormatDateTime('yyyy-m-d', t);        //2009-5-20

 if TryEncodeDateWeek(2009, 21, t) then
  s := FormatDateTime('yyyy-m-d', t);        //2009-5-18

 if TryEncodeDateMonthWeek(2009, 5, 3, 3, t) then
  s := FormatDateTime('yyyy-m-d', t);        //2009-5-20

 if TryEncodeDayOfWeekInMonth(2009, 5, 3, 3, t) then
  s := FormatDateTime('yyyy-m-d', t);        //2009-5-20
end;


end.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved