Is it possible to change the order of the Time Stamp?

Started by Dwev, February 17, 2021, 06:13:20 PM

Previous topic - Next topic

Dwev

Above every post there's a time stamp with the number for the reaction, for instance "Reply #1: Today at 04:07:09 PM"

The code for this in Display.template.php for our forum is as follows (the word "on" is already removed):


<div class="smalltext">', !empty($message['counter']) ? $txt['reply_noun'] . ' #' . $message['counter'] : ' ', ' ', $message['time'], '</div>


I was wondering if it's possible to change the order, so that it would be as follows: "Today at 04:07:09 PM - Reply #1".
Does anyone know what code I can use for this? (tried quite some variations, but keep getting errors and the forum stops working).

Thank in advance.

shadav

I'm not quite sure but going by what you posted, i haven't tried, I'd say something like

<div class="smalltext">', !empty($message['counter']) ? ', $message['time'], ' -  $txt['reply_noun'] . ' #' . $message['counter']' ', '</div>

Matthias

Have a look at 
Administration Center » Features and Options » General
Default time format

There you can change the time format for your needs.


Time Format
You have the power to adjust how the time and date look for yourself. There are a lot of little letters, but it's quite simple. The conventions follow PHP's strftime function and are described as below (more details can be found at php.net).

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.


Time offset is available at every user profile for themselves:
Profile of {user} » Look and Layout
Time Offset
Quality first

shadav

 ;D not quite what they were asking for though but handy to know

on display.template.php they want to change the wording around from message number : timestamp to timestamp - message number

Antechinus

<div class="smalltext"> ', $message['time'], ' - ', !empty($message['counter']) ? $txt['reply_noun'] . ' #' . $message['counter'] : ' ', '</div>


Should work.

Dwev

Quote from: Antechinus on February 17, 2021, 07:00:37 PM
<div class="smalltext"> ', $message['time'], ' - ', !empty($message['counter']) ? $txt['reply_noun'] . ' #' . $message['counter'] : ' ', '</div>


@shadav and Antechinus: thanks a lot, that worked like a charm!
The only snag turned out the hyphen (-) between the time and the reaction number, because that looked strange on the very first reaction (that doesn't have a number, of course).

So I replaced the hyphen with two non-breaking spaces, so the final code is this:


<div class="smalltext"> ', $message['time'], ' &nbsp&nbsp ', !empty($message['counter']) ? $txt['reply_noun'] . ' #' . $message['counter'] : ' ', '</div>

Antechinus

You can do it like this instead, if you want a hyphen once posts have numbers:

<div class="smalltext"> ', $message['time'] !empty($message['counter']) ? ' - ' . $txt['reply_noun'] . ' #' . $message['counter'] : ' ', '</div>

Advertisement: