Date Formating

Vino vino.bheeman at hotmail.com
Wed Dec 13 17:16:46 UTC 2017


On Wednesday, 13 December 2017 at 08:32:34 UTC, codephantom wrote:
> On Wednesday, 13 December 2017 at 07:35:40 UTC, Jonathan M 
> Davis wrote:
>> In general, you probably want to cast the SysTime to a 
>> DateTime if you're going to do something like that.
>
> yes, I would agree ;-)
>
> Of course the intention was not really to just format it the 
> same way as Clock.currTime() does it, but rather to provide a 
> way to more easily customise the format, however one likes, 
> whenever one likes..
>
> e.g.the following small change to the format string would make 
> it return: 20171213_1924_41
>
> (that's more like something I'd use)
>
>   return
>             format("%04s%02s%02s_%02s%02s_%02s",
>                 (d.year),
>                 to!(int)(d.month),
>                 (d.day),
>                 (d.hour),
>                 (d.minute),
>                 (d.second)
>                 );

Hi All,

  Request your help on below program on how to format or cast 
SysTime to DateTime

import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln,writefln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;
void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\\EXPORT"];
Array!(Tuple!(string, SysTime)) Sorted;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));
foreach(i; dFiles[]){ Sorted ~= i; }
writefln("%(%-(%-63s %s %)\n%)", Sorted[].sort!((a,b) => a[1] < 
b[1]));
}
}

Output:
C:\Temp\BACKUP\DND3                                     
2017-Sep-05 14:31:00.7037169
C:\Temp\BACKUP\DND5                                     
2017-Sep-05 14:31:00.750517
C:\Temp\EXPORT\DND6                                     
2017-Sep-05 14:31:00.8909172
C:\Temp\BACKUP\dir1                                     
2017-Sep-06 16:06:42.7223837
C:\Temp\EXPORT\dir2                                     
2017-Sep-06 16:06:43.1435864
C:\Temp\BACKUP\dir2                                     
2017-Sep-09 22:44:11.7604069
C:\Temp\BACKUP\dir3                                     
2017-Dec-10 06:56:07.5122231
C:\Temp\BACKUP\t1                                       
2017-Dec-11 04:10:02.6413853

Required Output
C:\Temp\BACKUP\DND3                                     
2017-Sep-05 14:31:00
C:\Temp\BACKUP\DND5                                     
2017-Sep-05 14:31:00
C:\Temp\EXPORT\DND6                                     
2017-Sep-05 14:31:00
C:\Temp\BACKUP\dir1                                     
2017-Sep-06 16:06:42
C:\Temp\EXPORT\dir2                                     
2017-Sep-06 16:06:43
C:\Temp\BACKUP\dir2                                     
2017-Sep-09 22:44:11
C:\Temp\BACKUP\dir3                                     
2017-Dec-10 06:56:07
C:\Temp\BACKUP\t1                                       
2017-Dec-11 04:10:02

From,
Vino.B



More information about the Digitalmars-d-learn mailing list