[Pharo-dev] Formatting dates

Chris Cunningham cunningham.cb at gmail.com
Wed Oct 30 17:34:21 EDT 2013


Or:

Date today printFormat: #(3 2 1 0 1 1 2)


On Wed, Oct 30, 2013 at 2:13 PM, Frank Shearar <frank.shearar at gmail.com>wrote:

> On 30 October 2013 20:55, blake <dsblakewatson at gmail.com> wrote:
> > Heya, guys--
> >
> > Converting a Ruby program to Pharo, and one of the things this program
> does
> > is write a file out by date. The format is "yyyymmdd" (which is my
> preferred
> > naming convention). In Ruby I have:
> >
> > "%04d" % d.year + "%02d" % d.month + "%02d" % d.day
>
> Why not "%04d%02d%02d" % [d.year, d.month, d.day] ?
>
> > In Smalltalk, the closest I can seem to get to this is:
> >
> > d year asString, (d monthIndex asString padLeftTo: 2 with: $0), (d
> > dayOfMonth asString padLeftTo: 2 with: $0)
> >
> > ...which seems sort verbose. Anyone have any more elegant solutions?
>
> Chris has already given a near solution. You just need to "select:
> #isDigit" on the end of his answer to get exactly what you want.
>
> frank
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20131030/f6cdea3c/attachment-0002.html>


More information about the Pharo-dev mailing list