1. Home
  2. Computing & Technology
  3. Delphi Programming
RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Essentials|Books|Link Back
 
TXDateTime
TXDateTime is a class designed to handle different formats of date and time used by Windows and Delphi. Full source code.
 Win prizes by sharing code!
Do you have some Delphi code you want to share? Are you interested in winning a prize for your work?
Delphi Programming Quickies Contest
 Join the Discussion
"Post your views, comments, questions and doubts to this article."
Discuss!
 Related Resources
• Using VCL components
• Creating components
• Date and Time routines

Article submitted by: Michael Klaus for the Delphi Programming Quickies Contest.

   TXDateTime
When creating an instance of the TXDateTime class (TXDateTime.Create), it will internaly save the current date and time.
Additionally, the class publishes two functions called MaxXDateTime and MinXDateTime, which return the latter or earlier instance, resp.
You can assign an Owner to the TXDateTime instance (.Owner:=) which will be invalidated if any content of TXDateTime changes.

Properties and methods:
The public methods are as follows:
· function AsDateTime:TDateTime; returns the currently saved date and time value in the TDateTime format Delphi uses.
· function AsDate:TDateTime; returns the currently saved date value in the TDateTime format Delphi uses.
· function AsTime:TDateTime; returns the currently saved time value in the TDateTime format Delphi uses.
· function AsDateString:string; returns the currently saved date value as string
· function AsDistTimeString:string; returns the currently saved date and time value as time distance string
· function AsIntDateString:string; returns the currently saved date value in the format yyyy-mm-dd
· function AsTimeString:string; returns the currently saved time value as string
· function AsDateTimeString:string; returns the currently saved date and time value as string
· function AsShortString(what:TXDTPieces):string; returns the currently saved date value according to the contents of "what" by the value of "by" (might also be negative!)
· function AsShortString6:string; returns the currently saved date value using the format yymmdd
· function AsFileTime:TFileTime; returns the currently saved date and time value in the TFileTime type used by API routines
· function AsSystemTime:TSystemTime; returns the currently saved date and time value in the TSystemTime type used by API routines
· function DayOfWeek:integer; returns the day of week of the currently saved date according to your local settings
· procedure FromDate(source:TDateTime); takes a TDateTime and reads the Date content
· procedure FromTime(source:TDateTime); takes a TDateTime and reads the Time content
· procedure FromDateTime(source:TDateTime); takes a TDateTime and reads Date and Time content
· procedure FromSystemTime(source:TSystemTime); takes a TSystemTime and reads Date and Time content
· procedure FromFileTime(source:TFileTime); takes a TFileTime and reads Date and Time content
· procedure FromString(source:string); takes a string (dd.mm.yyyy hh:mm:ss.ms) and reads Date and Time content
· procedure Assign(Source:TPersistent); override; takes the values of another TXDateTime
· procedure IncDateTime(what:TXDTPiece; by:integer); increments the part indicated by by the value of (might also be negative!)
· function Clone:TXDateTime; creates an exact copy of itself

The published properties are as follows:
· property Day:integer read FDay write SetDay;
· property Month:integer read FMonth write SetMonth;
· property Year:integer read FYear write SetYear;
· property Hour:integer read FHour write SetHour;
· property Minute:integer read FMinute write SetMinute;
· property Second:integer read FSecond write SetSecond;
· property MilliSecond:integer read FMilliSecond write SetMilliSecond;
· property ShowSecond:boolean read FShowSecond write SetShowSecond; whether or not seconds are shown
· property ShowMillisecond:boolean read FShowMillisecond write SetShowMillisecond; whether or not milliseconds are shown. In order to show milliseconds, you have to show seconds as well.

Download full source code!

Of course, if you have any question please post and discuss on the Delphi Programming Forum

All graphics (if any) in this feature created by Zarko Gajic.

 More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2003|2002|2001|2000|1999|1998 or by TOPIC.
 Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.