A
Allen Young
Hi all,
I want to parse some strings into Date object and I find in rdoc that
strptime is the right place to go. For some formats of string it's
really easy to parse it. For instance, '%Y.%m.%d' will parse something
like '2007.09.12'. But I have two kinds of string that I don't now how
to parse.
'20070912': there is no '.', '-' or '/' as the seperator and '%Y%m%d'
doesn't work, it will throw an exception saying that: "ArgumentError: 3
elements of civil date are necessary".
'2007.09': in this kind of string, I don't care about the exactly
date(in fact, the data I received is lacked of that information). As a
result, '%Y.%m' doesn't work with the same error as above.
How can I deal with this two kinds of string? Thanks a lot.
I want to parse some strings into Date object and I find in rdoc that
strptime is the right place to go. For some formats of string it's
really easy to parse it. For instance, '%Y.%m.%d' will parse something
like '2007.09.12'. But I have two kinds of string that I don't now how
to parse.
'20070912': there is no '.', '-' or '/' as the seperator and '%Y%m%d'
doesn't work, it will throw an exception saying that: "ArgumentError: 3
elements of civil date are necessary".
'2007.09': in this kind of string, I don't care about the exactly
date(in fact, the data I received is lacked of that information). As a
result, '%Y.%m' doesn't work with the same error as above.
How can I deal with this two kinds of string? Thanks a lot.