DateTime objectFormatting

Chris Rebert clp2 at rebertia.com
Wed May 2 10:57:05 EDT 2012


On Wed, May 2, 2012 at 7:49 AM, Nikhil Verma <varma.nikhil22 at gmail.com> wrote:
<snip>
>     def __unicode__(self):
>         return "%s %s" % (self.name, self.date_created.strftime("%A %B %d"))
>
>
> The user fills Gen GI in name and date along with time.
>
> What i am able to achieve with this class object to return is :-
>
> Gen GI Monday  May 7
>
> I want that the this class should return object like this :-
>
> Gen GI Monday AM, May 7
> Pancreas Tuesday PM, May 8
>
> How can achieve AM and PM also ? with this datetime object

Consult the docs.
http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior :
"%p	-- Locale’s equivalent of either AM or PM."

So, strftime("%A %p, %B %d").

Regards,
Chris



More information about the Python-list mailing list