News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Is there a time zone code for the default forum time zone?

Started by PrimalPrime, May 18, 2023, 03:32:11 PM

Previous topic - Next topic

PrimalPrime

Hi, I was hoping to include the time zone when it shows the timestamp. I would attach screenshot but I guess I am not allowed and I can't post a link to it either. But it is this code: %m.%d.%Y %I:%M %p.  Thank you very much.



Aleksi "Lex" Kilpinen

You would have to have that outside of the actual timestamp, meaning that you would need to code that separately.

The following characters are recognized in the format string:
  %a - abbreviated weekday name
  %A - full weekday name
  %b - abbreviated month name
  %B - full month name
  %d - day of the month (01 to 31)
  %D* - same as %m/%d/%y
  %e* - day of the month (1 to 31)
  %H - hour using a 24-hour clock (range 00 to 23)
  %I - hour using a 12-hour clock (range 01 to 12)
  %m - month as a number (01 to 12)
  %M - minute as a number
  %p - either "am" or "pm" according to the given time
  %R* - time in 24 hour notation
  %S - second as a decimal number
  %T* - current time, equal to %H:%M:%S
  %y - 2 digit year (00 to 99)
  %Y - 4 digit year
  %% - a literal '%' character

* Does not work on Windows-based servers.

You can not simply write your default timezone in there either, since any user can configure a different time zone for themselves and the forum will adjust accordingly for them.

EDIT:
I was wrong actually, you could perhaps just add UTC %z to the string, to show time offset from UTC.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

PrimalPrime


Aleksi "Lex" Kilpinen

Quote from: Aleksi "Lex" Kilpinen on May 18, 2023, 03:56:26 PMEDIT:
I was wrong actually, you could perhaps just add UTC %z to the string, to show time offset from UTC.
Just tried this, it is apparently OS dependant, so may not work on all server platforms - but works for me.
You could play around with these https://www.php.net/manual/en/function.strftime.php
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Sesquipedalian

Actually, in SMF 2.1, %z and %Z will work correctly even on Windows. This is because SMF 2.1 accepts strftime format strings, but internally does not use strftime to process them. Instead, we use a translation layer to convert strftime format strings into PHP's native DateTime format strings, and then use DateTime to process them.

We made this change in SMF 2.1 because strftime is deprecated in PHP 8.1+.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Aleksi "Lex" Kilpinen

The admin help popup should be updated then. ;) That's what lead me to believe z would not work. It's not listed at all.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Sesquipedalian

Quote from: Aleksi "Lex" Kilpinen on May 19, 2023, 01:15:45 AMThe admin help popup should be updated then. ;) That's what lead me to believe z would not work. It's not listed at all.

It probably should.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Advertisement: