4๐
You need to add a single line to the settings.py
file and it will change the time formatting across all the apps in your project.
add this to the settings.py
file:
- If you want the 12 Hr clock formatting with AM/PM:
TIME_INPUT_FORMATS = ('%I:%M %p',)
- If you want 24 Hour clock formatting:
TIME_INPUT_FORMATS = ('%H:%M',)
1๐
in setting.py add
'DATETIME_FORMAT': "%m-%d - %M:%S"
in models.py
temps_preparation = models.DateTimeField(null=True)
and in form.py
datetime.strptime(yourdate, "%M:%S")
๐คMaede
0๐
You can format dates directly in the html template (docs)
<p>{{ your_date|date:"h:iA" }}</p>
or in the view (docs)
your_date.strftime("%I:%M%p")
In the example above I used the 12-hours format.
๐คDos
- [Django]-Create a git repo for project skeleton
- [Django]-Django adding a feedback form on every page
- [Django]-Django Channels 2.0 channel_layers not communicating
- [Django]-Django template tag + template with user.is_authenticated doesn't work
- [Django]-Junk after document element: line 13, column 2
- [Django]-Get distinct django objects from queryset sorted by latest
- [Django]-Django: Force cache-refresh after update
Source:stackexchange.com