AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Free pascal datetime7/28/2023 ![]() When the above code was compiled and executed, it produced following result: Date: 4.195700000000000E+004 YY ,MM ,DD : Word begin writeln ( 'Date : ' ,Date ) DeCodeDate (Date ,YY ,MM ,DD ) writeln ( format ( 'Today is (DD/MM/YY): %d/%d/%d ', ) ) The following program demonstrates how to use it in your program to display the current date: Program DateDemo uses sysutils var The TDateTime is a double value, which needs some decoding and formatting. The Date function returns the current date in TDateTime format. When the above code was compiled and executed, it produced following result: Current time : 18:33:08 The following example shows how to get the current time: program TimeDemo uses sysutils begin writeln ( 'Current time : ', TimeToStr (Time ) ) end. ![]() ![]() Pascal's TimeToString function gives you the current time in a colon(: ) delimited form. However, the actual name and workings of these functions are different for different compilers. Pascal also provides powerful tools for date arithmetic that makes manipulating dates easy. Dates are so much part of everyday life that it becomes easy to work with them without thinking. Most of the software you write needs implementing some form of date functions returning current date and time. ToString end var aDateTime : TDateTime begin aDateTime := now WriteLn ( 'Date: ' + FormatDateTime ( 'yyyy-mm-dd', aDateTime )) // WriteLn ( 'Combined date and time in UTC: ' ) WriteLn ( ' ' + ISO8601_Combined_date_and_time_in_UTC ( aDateTime, '+00:00' )) // T12:18:47+00:00 WriteLn ( ' ' + FormatDateTime ( 'yyyymmdd"T"hhmmss', aDateTime ) + 'Z' ) // 20180926T121847Z Writeln ( ' ' + ISO8601_Combined_date_and_time_in_UTC ( aDateTime, 'Z' )) // WriteLn ( 'Week: ' + ISO8601_week ( aDateTime ) ) // 2018-W39 WriteLn ( 'Date with week number: ' + ISO8601_Date_with_week_number ( aDateTime )) // 2018-W39-3 WriteLn ( 'Ordinal date: ' + ISO8601_Ordinal_date ( aDateTime )) // 2018-269 ReadLn end. 2018-269 function ISO8601_Ordinal_date ( a_DateTime : TDateTime ) : string begin result := FormatDateTime ( 'yyyy', a_DateTime ) + '-' + ( DayOfTheYear ( a_DateTime )). ToString + '-' + ( DayOfTheWeek ( a_DateTime )). 2018-W39-3 function ISO8601_Date_with_week_number ( a_DateTime : TDateTime ) : string begin result := FormatDateTime ( 'yyyy', a_DateTime ) + '-W' + ( WeekOf ( a_DateTime )). ToString end // Date with week number: e.g. 2018-W39 function ISO8601_week ( a_DateTime : TDateTime ) : string begin result := FormatDateTime ( 'yyyy', a_DateTime ) + '-W' + ( WeekOf ( a_DateTime )). Program iso_8601_project Uses SysUtils, DateUtils // Combined date and time in UTC e.g // function ISO8601_Combined_date_and_time_in_UTC ( a_DateTime : TDateTime a_Time_zone : string ) : string begin result := FormatDateTime ( 'yyyy-mm-dd"T"hh:mm:ss', a_DateTime ) + a_Time_zone end // Week: e.g. Gives the week of the year for a TDateTime value Gives a string representation of a TDateTime value with a given format Gives the day of the year for a TDateTime value Gives day of week index for a TDateTime value Gives day of month index for a TDateTime value The time zone can be indicated by marking the time difference between the coordinated universal time (UTC) as follows: The combined date and time should be marked with the letter "T":īut often the intermediate letter "T" can be replaced by a space. The SS is seconds from the beginning of the previous minute between 00 and 59. The MM is minutes from the beginning of the previous hour between 00 and 59. Where HH has hours after midnight between 00 and 23. Where YYYY is a year in the Gregorian calendar, MM is a month between 01 (January) and 12 (December), and DD is the day of the month between 01 and 31. ISO 8601 is a standard issued by the International Organization for Standardization (ISO) for the date and time.Īccording to ISO 8601, the date is as follows:
0 Comments
Read More
Leave a Reply. |