Wednesday 15 June 2011

Display time format as (MM/DD/YYYY - HH:MM AM/PM) - Django/Python -


Under the "Send_mail" function, I would like to change the "Start" variable to display as the date / time MM / DD / YYYY - HH: MM AM / PM In the email do anyone know how to do this is?

Thanks in advance!

  date = coerce_date_dict (request.GET) initial_data = none of the date: try: start = datetime.datetime (date **) initial_data = {"start": start, "end" : Start + datetime.timedelta (min = 60)} Exclude writing error: Http404 except ValueError: Http404 enhanced example = If none does, event_id does not have any: example = get_object_or_404 (event, id = event_id) calendar = Get_object_or_404 (calendar, slug = calendar_slug) form = form_class (data = request. POST or none, example = example, initial = initial_data) if form.is_valid (): event = form.save (commit = False) If the example is none: event.creator = request.user Event Calendar = Try Calendar: send_mail ('New Text', '% s'% s'% (request.user.full_name, Start) for a New lesson is determined, except 'example@gmail.com', ['example@gmail.com ']): pass event.save () next = next or reverse (' event ', args = [eve nt. Id]) next = get_next_url (request, adjacent) return to HttpResponseRedirect (next)  

Start is an object, so we need to generate a formatted string Method can call.

You want the format specifier % m /% d /% Y% I:% M% p

for example, the current time (my StripTime Method: 03/17/2015 05:51 PM

We can easily download your code In this way you can integrate:

  start = datetime.datetime (** date) Initial_data = {"start": start.strftime ("% m /% d /% Y% I :% M% p ")," end ": start + datetime.timedelta (minutes = 60)}  

Note: Make sure you make this change and the other "Down the road" does not violate - initial_data ['start'] as was a datetime.datetime object, and now There is a string.


No comments:

Post a Comment