How do I create UK dates from strings in Pharo Smalltalk?
Asked Answered
L

1

6

I have some code that successfully parses strings to create dates:

date := string asDate

But this assumes US date format mm/dd/yyyy.

I know I can output a date as a string in UK format like this:

date printFormat: #(1 2 3 $/ 1 1)

So my question, how do I create a date from a UK format date string dd/mm/yyyy?

I've checked the String>>asDate method and this doesn't have any format parameter. Looking at Date class>>readFrom: (which asDate calls) it seems to have UK code in there, but how to dictate that this is what I want?

Lamprey answered 19/3, 2013 at 20:25 Comment(1)
Which Pharo version? the default in Pharo 2.0 is dd mm yyyy: '01-01-1901' asDate or 'January 1, 1901' asDate. Maybe you want to check sending #ddmmyyyy to the date? Can you post your parser?Selwyn
J
7

Would this work for you?

Date readFrom: '04/02/2013' readStream pattern: 'dd/mm/yyyy'
Jameejamel answered 20/3, 2013 at 1:20 Comment(1)
Yes, that's it. I forgot to look at the class messages of Date.Lamprey

© 2022 - 2024 — McMap. All rights reserved.