Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Date-manipulation/D/date-manipulation.d
Normal file
30
Task/Date-manipulation/D/date-manipulation.d
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import std.stdio;
|
||||
import std.format;
|
||||
import std.datetime;
|
||||
import std.algorithm;
|
||||
|
||||
enum months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
||||
|
||||
void main()
|
||||
{
|
||||
// input
|
||||
string date = "March 7 2009 7:30pm EST";
|
||||
|
||||
// parsing date string to integer values
|
||||
string month, md, tz;
|
||||
int day, year, hour, minute;
|
||||
date.formattedRead("%s %d %d %d:%d%s %s", &month, &day, &year, &hour, &minute, &md, &tz);
|
||||
int mon = cast (int) months.countUntil(month) + 1;
|
||||
|
||||
// convert to 24-hour
|
||||
if (md == "pm")
|
||||
hour += 12;
|
||||
|
||||
// create date from integer
|
||||
DateTime dt = DateTime(year, mon, day, hour, minute);
|
||||
|
||||
// output
|
||||
writeln(dt);
|
||||
writeln(dt + 12.hours);
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue