note
Ultimatt
<p>Re: what would this look like in Perl6...</p>
<p>First of all you wouldn't do this in Perl6 if you could help it! You would just use the built in core DateTime object and then use the attributes on that object to get the bits of the date and time you want >;3 If you grab yourself a copy of Rakudo the following works from the command line REPL:</p>
<code>
$ perl6
> my $time = DateTime.new(time)
2014-11-05T22:35:54Z
> $time.^methods
check-time now clone clone-without-validating Instant posix offset offset-in-minutes offset-in-hours later earlier truncated-to whole-second in-timezone utc local Date Str IO is-leap-year days-in-month daycount-from-ymd ymd-from-daycount get-daycount day-of-month day-of-week week week-year week-number weekday-of-month day-of-year check-value check-date truncate-parts new perl gist <anon> <anon> <anon> <anon> <anon> <anon> <anon> <anon>
> $time.^attributes
Int $!year Int $!month Int $!day Int $!hour Int $!minute Mu $!second Mu $!timezone Callable &!formatter
> say $time.month
11
>
</code>
<p>DateTime.new(time) above is the current local time as an object. Just time on its own gives you an Int as the system epoch timestamp in seconds. Calling ^methods on anything gives you a list of the methods an object has which is useful for picking up Perl6, ^attributes is similarly useful and makes it fairly obvious what you can get at in DateTime.</p>
1105972
1105972