Date manipulation: Difference between revisions
Content added Content deleted
(Add Crystal) |
(Add Rust implementation) |
||
Line 2,582: | Line 2,582: | ||
print date$(d);" ";t1$;ap$</lang><pre>03/08/2009 7:30am</pre> |
print date$(d);" ";t1$;ap$</lang><pre>03/08/2009 7:30am</pre> |
||
=={{header|Rust}}== |
|||
<lang rust> |
|||
use chrono::prelude::*; |
|||
use chrono::Duration; |
|||
fn main() { |
|||
// Chrono allows parsing time zone abbreviations like "EST", but |
|||
// their meaning is ignored due to a lack of standardization. |
|||
// |
|||
// This solution compromises by augmenting the parsed datetime |
|||
// with the timezone using the IANA abbreviation. |
|||
let ndt = |
|||
NaiveDateTime::parse_from_str("March 7 2009 7:30pm EST", "%B %e %Y %l:%M%P %Z").unwrap(); |
|||
// add TZ manually |
|||
let dt = chrono_tz::EST.from_local_datetime(&ndt).unwrap(); |
|||
println!("Date parsed: {:?}", dt); |
|||
let new_date = dt + Duration::hours(12); |
|||
println!("+12 hrs in EST: {:?}", new_date); |
|||
println!( |
|||
"+12 hrs in CET: {:?}", |
|||
new_date.with_timezone(&chrono_tz::CET) |
|||
); |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
Date parsed: 2009-03-07T19:30:00EST |
|||
+12 hrs in EST: 2009-03-08T07:30:00EST |
|||
+12 hrs in CET: 2009-03-08T13:30:00CET |
|||
</pre> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
<lang scala>import java.text.SimpleDateFormat |
<lang scala>import java.text.SimpleDateFormat |
||
Line 2,604: | Line 2,637: | ||
<pre>March 8 2009 8:30AM EDT |
<pre>March 8 2009 8:30AM EDT |
||
March 8 2009 12:30PM GMT</pre> |
March 8 2009 12:30PM GMT</pre> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |