demodatetime.pas 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. program demodatetime;
  2. uses sysutils, js;
  3. Procedure DumpDate(Msg : String; Dt : TDateTime);
  4. Var
  5. Y,M,D : Word;
  6. begin
  7. DecodeDate(Dt,Y,M,D);
  8. Writeln(Msg,' : ',Y,'-',M,'-',D,' (',Dt,')');
  9. end;
  10. Procedure DumpTime(Msg : String; Dt : TDateTime);
  11. Var
  12. H,M,S,Z : Word;
  13. begin
  14. DecodeTime(Frac(Dt),H,M,S,z);
  15. if z<>0 then
  16. Writeln(Msg,' : ',H,':',M,':',S,'.',z,' (',Frac(Dt),')')
  17. else
  18. Writeln(Msg,' : ',H,':',M,':',S,' (',Frac(Dt),')')
  19. end;
  20. Procedure DumpDateTime(Msg : String; Dt : TDateTime);
  21. Var
  22. Y,Mo,Da,H,M,S,Z : Word;
  23. begin
  24. DecodeDate(Dt,Y,Mo,Da);
  25. DecodeTime(Frac(Dt),H,M,S,z);
  26. if z<>0 then
  27. Writeln(Msg,' : ',Y,'-',Mo,'-',Da,' ',H,':',M,':',S,'.',z,' (',Dt,')')
  28. else
  29. Writeln(Msg,' : ',Y,'-',Mo,'-',Da,' ',H,':',M,':',S,' (',Dt,')')
  30. end;
  31. Var
  32. Dt : TDateTime;
  33. begin
  34. Dt:=Date;
  35. DumpDate('Date',Dt);
  36. Dt:=Time;
  37. DumpTime('Time',dt);
  38. Dt:=Now;
  39. DumpDateTime('Now',Dt);
  40. Writeln('DateToStr : ',DateToStr(Dt));
  41. Writeln('TimeToStr : ',TimeToStr(Dt));
  42. DumpTime('StrToTime',StrToTime('14:15:16'));
  43. DumpDate('StrToDate (yyyy-mm-dd)',StrToDate('2016-10-12'));
  44. ShortDateFormat:='mm-dd-yyyy';
  45. DumpDate('StrToDate (mm-dd-yyyy)',StrToDate('10-16-2016'));
  46. ShortDateFormat:='dd-mm-yyyy';
  47. DumpDate('StrToDate (dd-mm-yyyy)',StrToDate('17-10-2016'));
  48. end.