VERSION using ICU using Calendar n=now() whos(ICU) ICU.getDefaultTimeZone() ICU.getNow() #epoch in milliseconds as a Float64 zcal=ICU.ICUCalendar("UTC") dump(zcal) lcal=ICU.ICUCalendar() dump(lcal) ICU.get(zcal, UCAL_MONTH) ICU.get(zcal, [UCAL_MONTH, UCAL_DATE, UCAL_YEAR, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET])' ldt = ICU.get(lcal, [UCAL_MONTH, UCAL_DATE, UCAL_YEAR, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET])' # timezone offset in hours ldt[4]/1000/3600 ICU.setDate(lcal, 2011, 11, 1) millis = ICU.getMillis(lcal) fmt=ICU.ICUDateFormat("yyyy", "UTC") #ICU.format(ICUDateFormat, millis) ifmt1 = ICU.format(fmt, millis) ICU.getTimeZoneDisplayName(lcal) whos(Calendar) t0=Calendar.now() t = ymd_hms(2013, 3, 10, 1, 59, 59) typeof(t) t + days(2) delta =t0-t t + delta dump(delta) s = Calendar.format("yyyy-MMMM-dd EEE HH:mm:ss x", t) t2 = Calendar.parse("yyyy-MMMM-dd EEE HH:mm:ss V", s) timezone(t2, "UTC") dayofyear(today()) println("Today is day $(dayofyear(today())) of the current year.") println("Today is day $(dayofyear(today())) of $(year(today())).") println("The date is $(today()).") now() epoch_dt = ymd_hms(1970,1,1,0,0,0,"UTC") now() - epoch_dt (now() - epoch_dt).millis dt=now() dump(dt) dt.millis / 1000 function CalTime2epoch(caltime) return caltime.millis/1000 end CalTime2epoch(today()) epoch_dt epoch_time = time() function epoch2CalendarTime(epoch) epoch_dt = ymd_hms(1970,1,1,0,0,0,"UTC") return epoch_dt + seconds(epoch) end epoch2CalendarTime(epoch_time) mydate = ymd(2013,1,2) println("One day in the future is $(mydate + days(1))") println("Two weeks in the past is $(mydate + weeks(-2))") dt2 = ymd(2013,2,14) dt2 - mydate birthtime = ymd_hms(1973,1,18,3,45,50) then = birthtime + seconds(5)+minutes(17)+hours(2)+days(55) println("Then is $then") when = ymd(1973,1,18) + days(55) println("Nat was 55 days old on $when") diff = dt2 - mydate dump(diff) dt1 = now() dt2 = now() diff_dt = dt2-dt1 dump(diff_dt) bree = ymd_hms(1981,6,16,4,35,25) nat = ymd_hms(1973,1,18,3,45,50) dtdiff=bree-nat dump(dtdiff) dur2seconds(dur) = int(floor(dur.millis/1000)) dur2minutes(dur) = int(floor( (dur.millis/1000) / 60)) dur2hours(dur) = int(floor( (dur.millis/1000) / 3600)) dur2days(dur) = int(floor( (dur.millis/1000) / 86400 )) dur2weeks(dur) = int(floor( (dur.millis/1000) / 86400 / 7 )) dur2days( dtdiff ) println("There were $(dur2days(dtdiff)) days between Nat and Bree") wks = dur2weeks(dtdiff) days = dur2days(dtdiff) netdays = days - wks*7 hrs = dur2hours(dtdiff) nethours = hrs - days*24 mins = dur2minutes(dtdiff) netmins = mins - 60*hrs netsecs = dur2seconds(dtdiff) - 60*mins wks,netdays, nethours, netmins, netsecs println("$wks weeks, $netdays days, $nethours:$netmins:$netsecs") when = ymd(1981,6,16) dayofweek(when) # = Tuesday year(when), month(when), day(when) format("yyyy", when) t = ymd_hms(2013, 3, 10, 1, 59, 59) s = format("yyyy-MMMM-dd HH:mm:ss V", t) #strftime("Today is Day %w of the week (a %A). Day %d of the month (%B)",Datetime.today()) td = today() #('MMMM')'", td) format("'Today is Day ' c ' of the week (a ' eeee'). '",td) * format("'Day' d 'of the month ('MMMM').'",td) # Tuesday #strftime("1981-06-16 was Day %w of the week (a %A). Day %d of the month (%B)",when) format("'Today is Day ' c ' of the week (a ' eeee'). '",when) * format("'Day' d 'of the month ('MMMM').'",when) format("'Today is Day ' c ' of the week (a ' eeee'). Day' d 'of the month ('MMMM').'",when) # day of year: 168, week of year=24 #strftime("Day %j of the year(%Y), in week %W of the year.",when) format("'Day ' D ' of the year ('YYYY'), in week ' w 'of the year.'", when) Calendar.parse("EEE MMM DD HH:mm:ss yyyy", "Tue Jun 16 20:18:03 1981") #time.strptime("16/6/1981", "%d/%m/%Y") Calendar.parse("DD/M/yyyy","16/6/1981") cdt = Calendar.now() Calendar.format("'The date is 'YYYY",cdt) """The date is $(Calendar.format(" EEEE (EEE) d/MM/yyyy",cdt))""" Calendar.format("'The date is ' EEEE (EEE) d/MM/yyyy",cdt) tic() elapsed=toc() # from https://github.com/JuliaLang/julia/issues/4478 function f1(n) sum = 0.0 g1(k) = 1.0/k for i = 1:n sum += g1(i) end sum end f1(99) @time f1(1e6) sleep(3.1) #sleep for 4 seconds @time( sleep(3.1) ) ;ipython nbconvert 3_pleac_datetime-calendar.ipynb