Re: adding a time to a DT object
[email protected] ("Flavio S. Glock")
| Newsgroups | perl.datetime |
|---|---|
| Message-ID | <[email protected]> |
2008/9/26 Perrin Harkins <[email protected]>: > > The gist of what I wanted to do is this: > > - Take a DT object which has been truncated to day. > - Take a string like "10:30 AM". > - Set the time on the DT object according to that string. > how about: use DateTime::Incomplete; use DateTime::Format::Strptime; my $df = DateTime::Format::Strptime->new( pattern => "%I:%M %p" ); my $di = DateTime::Incomplete->today; for (qw| 09:15 10:30 11:25 |) { print $di->to_datetime( base => $df->parse_datetime("$_ AM") ), "\n"; } 2008-09-26T09:15:00 2008-09-26T10:30:00 2008-09-26T11:25:00 - Flávio S. Glock