Date manipulation: Difference between revisions

(4 intermediate revisions by 2 users not shown)
Line 1,796:
Langur currently uses the Go time package. Testing with Go 1.14.1 on Linux, the time package doesn't seem to parse "EST" correctly, and it seems to fail silently. Given these conditions, I use "-05:00" instead of "EST" in the input string.
 
{{works with|langur|0.10.1}}
<syntaxhighlight lang="langur">val .input = "March 7 2009 7:30pm -05:00"
val .iformat = "January 2 2006 3:04pm -07:00" # input format
val .formatoformat = "January 2 2006 3:04pm MST" # output format
 
val .d1 = toDateTimedatetime .input, .iformat
val .d2 = .d1 + dtdr/PT12H/
val .d3 = toDateTimedatetime .d2, "US/Arizona"
val .d4 = toDateTimedatetime .d2, ZLSzls
val .d5 = toDateTimedatetime .d2, "Z"
val .d6 = toDateTimedatetime .d2, "+02:30"
val .d7 = toDateTimedatetime .d2, "EST"
 
writeln "input string: ", .input
writeln "input format string: ", .iformat
writeln "output format string: ", .formatoformat
writeln()
 
writeln $"original: \.d1; (\.d1:dt.format oformat;)"
writeln $"+12 hours: \.d2; (\.d2:dt.format oformat;)"
writeln $"in Arizona: \.d3; (\.d3:dt.format oformat;)"
writeln $"in local time zone: \.d4; (\.d4:dt.format oformat;)"
writeln $"in UTC: \.d5; (\.d5:dt.format oformat;)"
writeln $"+02:30 time zone: \.d6; (\.d6:dt.format oformat;)"
writeln $"in EST: \.d7; (\.d7:dt.format oformat;)"</syntaxhighlight>
 
{{out}}
Line 1,973 ⟶ 1,972:
<syntaxhighlight lang="mathematica">dstr = "March 7 2009 7:30pm EST";
DateString[DatePlus[dstr, {12, "Hour"}], {"DayName", " ", "MonthName", " ", "Day", " ", "Year", " ", "Hour24", ":", "Minute", "AMPM"}]</syntaxhighlight>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">import "dateTime"
import "stringUtil"
 
months = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December",
]
 
date = "March 7 2009 7:30pm EST"
print "Original date/time : " + date
 
// change the date to standard format
items = date.split
month = months.indexOf(items[0]) + 1
day = items[1]
year = items[2]
time = items[3]
hour = time.split(":")[0].val
minute = time.split(":")[1][0:2]
pm = time.endsWith("pm")
if pm then hour = hour + 12
time = hour + ":" + minute
zone = items[4]
date = year + "-" + month + "-" + day + " " + time
 
// add 12 hours and display in original format
dval = dateTime.val(date) + 12*60*60
dfmt = "MMMM d yyyy h:mmtt"
date2 = dateTime.str(dval, dfmt) + " " + zone
print "12 hours later : " + date2
 
// change from EST to MST (2 hours earlier)
date3 = dateTime.str(dval - 2*60*60, dfmt) + " MST"
print "Adjusted to MST : " + date3</syntaxhighlight>
 
{{out}}
<pre>Original date/time : March 7 2009 7:30pm EST
12 hours later : March 8 2009 7:30am EST
Adjusted to MST : March 8 2009 5:30am MST
</pre>
 
=={{header|mIRC Scripting Language}}==
Line 3,308 ⟶ 3,349:
=={{header|Wren}}==
{{libheader|Wren-date}}
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
 
var fmt = "mmmm| |d| |yyyy| |H|:|MM|am| |zz|"
990

edits