June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 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