Recent

Author Topic: ctime to string  (Read 1889 times)

440bx

  • Hero Member
  • *****
  • Posts: 6540
ctime to string
« on: July 26, 2018, 05:13:27 pm »
hello,

I was wondering if anyone knew of an already written function/procedure in FPC to convert a ctime structure to its equivalent string date.

IOW, a routine that converts input such as:
Code: Pascal  [Select][+][-]
  1. ctime:        0   to date string: 1970/01/01 0:00:00
  2. ctime: 5AE5947B   to date string: 2018/04/29 9:46:35
  3. ctime: 521EAE52   to date string: 2013/08/29 2:13:38
  4.  

I have the C code to do the above which I can translate to FPC but, I figured maybe someone had already invented that wheel and tested it.

Thanks.



FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: ctime to string
« Reply #1 on: July 26, 2018, 06:05:26 pm »
Maybe this:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes, sysutils, dateutils
  10.   { you can add units after this };
  11.  
  12. begin
  13.   WriteLn(DateTimeToStr(UnixToDateTime($0)));
  14.   WriteLn(DateTimeToStr(UnixToDateTime($5AE5947B)));
  15.   WriteLn(DateTimeToStr(UnixToDateTime($521EAE52)));
  16.   ReadLn;
  17. end.

440bx

  • Hero Member
  • *****
  • Posts: 6540
Re: ctime to string
« Reply #2 on: July 26, 2018, 06:20:37 pm »
Thank you Engkin, that's all I need :) 
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018