1

I want to be able to conveniently change the default datetime format for my entire application.

How I plan to do this is by defining the format in a "constants" file that is included in all the other files. Then, I will use this format whenever I call my time formatting functions.

What are alternative implementations?

hakre
  • 193,403
  • 52
  • 435
  • 836
Dave
  • 3,328
  • 7
  • 26
  • 30
  • Do you mean for storing datetimes internally and processing them? Or do you mean for display purposes? – liquorvicar Nov 24 '11 at 09:44
  • I mean for storage, processing, and display. I have functions for formatting time for display and for converting it back to a storage-friendly format. – Dave Nov 24 '11 at 09:52

2 Answers2

3

Extract the functionality into a function or even class. This function respectively class method then can be used to get your datetime string in your desired formatting in all of your scripts. If you then need to change your timezone or your formatting, you only need to change the function or class method.

Thomas Tschernich
  • 1,264
  • 15
  • 29
1

You could use strftime() with the %c or %x format option for that, and set the locale to the correct value for the viewer. Be careful with it because setlocale() is not thread safe, so you shouldn't use that with threaded webservers (IIS, or apache with a threaded worker).

A related question: strtotime With Different Languages?

Community
  • 1
  • 1