?

Log in

No account? Create an account

Previous Entry | Next Entry

How To: Change The Date and Time Format

  • Sep. 3rd, 2006 at 12:32 PM
This can't be done with CSS - to do this you need to have a cutom layer or theme.

You need to change the lang_posted_by_date_and_time function, which is:

function lang_posted_by_date_and_time(EntryLite e, bool showposter, bool showdate, bool showtime) : string {
var string posted = "";
if ($showposter) {
var string posterstr = (defined $e.poster ? ""+$e.poster : """<i class="noposter">$*text_poster_anonymous</i>""");
if (not $showtime and not $showdate) {
return $posted;
}
}
if ($showdate and $showtime) {
if ($e.depth > 0) { # If $e is a comment
return $posted + $e->time_display("med", "");
} else {
return $posted + $e->time_display($*lang_fmt_date_med + " at %%h%%:%%min%% %%A%%M", "none");
}
}
if ($showdate and not $showtime) {
return $posted + $e->time_display("med", "none");
}
if (not $showdate and $showtime) {
return $e->time_display("none", "%%h%%:%%min%% %%A%%M");
}
return "";
}


In this, change these two lines:

return $posted + $e->time_display($*lang_fmt_date_med + " at %%h%%:%%min%% %%A%%M", "none");

return $posted + $e->time_display("med", "none");


, replacing $*lang_fmt_date_med with $*lang_fmt_date_med_day in the first and "med" with "med_day" in the latter.

This will give you the abbreviated day of the week at the start of the date and time. If you want the full day name, use $*lang_fmt_date_long_day and "long_day" respectively.

You can see all the date and time format options here.

Comments

( 17 comments — Leave a comment )
camomiletea
Sep. 3rd, 2006 08:38 pm (UTC)
You'll need to escape the HTML in the code, i.e. turn <i> into &lt;i&gt;
nimoloth
Sep. 3rd, 2006 08:48 pm (UTC)
Ah yes, thanks!
martygreene
Oct. 13th, 2006 05:18 pm (UTC)
I have my journal set to german, but want an english display of the date (ie. month, day, year, not day, month, year)

I've failed at figuring this out- any suggestions?
nimoloth
Oct. 14th, 2006 11:56 am (UTC)
month/day/year is American, not British - we use day/month/year, which makes much more sense! Anyhow, the American standared is the default, which is what you say you want.

In the function above, this is the key line:

return $posted + $e->time_display($*lang_fmt_date_med + " at %%h%%:%%min%% %%A%%M", "none");


If you've got that line as it is here, you should get:

Oct. 14th 2006 at 12:34am

If you change $*lang_fmt_date_med to $*lang_fmt_date_med_day you should see:

Sat, Oct. 14th 2006 at 12:34am

And if you change it to $*lang_fmt_date_short you should get:

10/14/06 at 12:34am

Which is month/day/year (American style). If you want to reverse this to day/month/year (British and European style), you'd have to do it manually - replace $*lang_fmt_date_med with the following, including the quotes:

"%%d%%/%%m%%/%%yy%%"

You can see all the custom options and how to customise your date at this link:

http://www.livejournal.com/doc/s2/siteapi.core1.html#siteapi.core1.dateformats

You should also replace "med" in this bit:

return $posted + $e->time_display("med", "none");


with whatever you replaced $*lang_fmt_date_med with.

However, I see that your journal is only showing the time. Is the problem that the date won't show at all?
martygreene
Oct. 14th, 2006 04:08 pm (UTC)
The issue falls when I set the default language for LJ to display as german, it changes things to suit how a german individual would expect to see things. It automatically changes the date to day-month-year, even though the code looks exactly the same. I'm guessing that's the *lang bit keying in.

It shows the date for me, though on entries where there is no title it makes the date the title, and then only has the time in the standard date slot.
nimoloth
Oct. 14th, 2006 11:59 am (UTC)
Sorry, I looked further down your list and I see what your date is showing as. So you want 14th October, 2006 instead of October 14th, 2006? That will also need to be a custom format. Replace $*lang_fmt_date_med with:

%%dayord%% %%month%%, %%yyyy%%

and replace "med" in

return $posted + $e->time_display("med", "none");

with the same.
nimoloth
Oct. 14th, 2006 12:00 pm (UTC)
%%dayord%% %%month%%, %%yyyy%%

Oh, and that needs to be in quotes, " ".
martygreene
Oct. 14th, 2006 04:09 pm (UTC)
ok... lemme try that...
martygreene
Oct. 14th, 2006 04:13 pm (UTC)
it's not changing... here's what I've got:

function lang_posted_by_date_and_time(EntryLite e, bool showposter, bool showdate, bool showtime) : string {
var string posted = "";
if ($showposter) {
var string posterstr = (defined $e.poster ? ""+$e.poster : """$*text_poster_anonymous""");
if (not $showtime and not $showdate) {
return $posted;
}
}
if ($showdate and $showtime) {
if ($e.depth > 0) { # If $e is a comment
return $posted + $e->time_display("%%dayord%% %%month%%, %%yyyy%%", "");
} else {
return $posted + $e->time_display("%%dayord%% %%month%%, %%yyyy%%" + " at %%h%%:%%min%% %%A%%M", "none");
}
}
if ($showdate and not $showtime) {
return $posted + $e->time_display("%%dayord%% %%month%%, %%yyyy%%", "none");
}
if (not $showdate and $showtime) {
return $e->time_display("none", "%%h%%:%%min%% %%A%%M");
}
return "";
}
nimoloth
Oct. 18th, 2006 08:57 am (UTC)
OK, I think I got it backwards - the whole British-American things confused me from the start! You want month-day-year, right, from reading your original comment?

This is the code for that format (i.e. October 14th, 2006):

"%%month%% %%dayord%%, %%yyyy%%"

As put in the places mentioned above. Hopefully that will work!
la_petite_singe
Feb. 25th, 2007 07:36 pm (UTC)
I know this was posted ages ago, but I'm still having trouble, sorry. :P I want it to be, like, Sunday, 25 February 2007, so I created this:

%%day%%,%% %%d%%month%%yyyy%%

but I'm just not sure where to place it in the code above. Sorry, I tried a bunch of things, but it just kept saying there were errors in the layer. Please help!
nimoloth
Feb. 26th, 2007 12:39 pm (UTC)
You need this format tag:

%%day%%, %%month%% %%dayord%% %%yyyy%%

Copy and paste the following code directly yo your custom theme:


function lang_posted_by_date_and_time(EntryLite e, bool showposter, bool showdate, bool showtime) : string {
var string posted = "";
if ($showposter) {
var string posterstr = (defined $e.poster ? ""+$e.poster : """<i class="noposter">$*text_poster_anonymous</i>""");
if (not $showtime and not $showdate) {
return $posted;
}
}
if ($showdate and $showtime) {
if ($e.depth > 0) { # If $e is a comment
return $posted + $e->time_display("long_day", "");
} else {
return $posted + $e->time_display($*lang_fmt_date_long_day + " at %%day%%, %%month%% %%dayord%% %%yyyy%%", "none");
}
}
if ($showdate and not $showtime) {
return $posted + $e->time_display("long_day", "none");
}
if (not $showdate and $showtime) {
return $e->time_display("none", "%%day%%, %%month%% %%dayord%% %%yyyy%%");
}
return "";
}


I've inserted the correct format code in there for you. Are you using a custom theme or a custom layer?
nimoloth
Feb. 26th, 2007 12:48 pm (UTC)
Sorry, I just tested it and in fact, this is the one you need to copy and paste to your custom theme/layer:

function lang_posted_by_date_and_time(EntryLite e, bool showposter, bool showdate, bool showtime) : string {
var string posted = "";
if ($showposter) {
var string posterstr = (defined $e.poster ? ""+$e.poster : """<i class="noposter">$*text_poster_anonymous</i>""");
if (not $showtime and not $showdate) {
return $posted;
}
}
if ($showdate and $showtime) {
if ($e.depth > 0) { # If $e is a comment
return $posted + $e->time_display("med", "");
} else {
return $posted + $e->time_display("%%day%%, %%month%% %%dayord%% %%yyyy%%" + " at %%h%%:%%min%% %%A%%M", "none");
}
}
if ($showdate and not $showtime) {
return $posted + $e->time_display("%%day%%, %%month%% %%dayord%% %%yyyy%%", "none");
}
if (not $showdate and $showtime) {
return $e->time_display("none", "%%h%%:%%min%% %%A%%M");
}
return "";
}
la_petite_singe
Feb. 26th, 2007 06:32 pm (UTC)
Thanks, that worked. :) If I want to change the size of the font of the date, does that go somewhere in there as well?
nimoloth
Feb. 26th, 2007 07:40 pm (UTC)
That's done through CSS - put this in your Custom CSS:

.datetime {font-size: 16pt; }

[with the font size of your choice, obviously - 16pt is pretty big!)
la_petite_singe
Feb. 26th, 2007 09:36 pm (UTC)
That one I'm having a little trouble with -- I tried the way you said, and all sort of variations, i.e., line-breaking it like this:

.datetime {
font-size: 13px;
}


like the other ones are, and putting "px" instead of "pt"...sorry if this one's obvious and I'm missing it. :P Am I just typing it wrong?
nimoloth
Feb. 27th, 2007 02:00 pm (UTC)
I had a look at your journal - I see you entry titles are the date and only the time displays below these. The CSS for .datetime will only affect the time in your journal. If you want to change the size of the entry titles (which are the date in your case because I assume you haven't specified a subject), you need to use:

.asset-name page-header2 {font-size: 16pt; }

Also, the syntax in my original is correct - I tested it on my journal. Better to use pt than px. Line breaks make no difference in CSS. Are you definitely putting it in your Custom CSS section under Edit Journal Style? If you put it there, it should have altered the size of the time in your entries.
( 17 comments — Leave a comment )

Latest Month

March 2016
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  

S2 Help Communities

Tags

Powered by LiveJournal.com
Designed by chasethestars