AlfieWebDevTips Homefor new and experienced developers
[Home Home] [Web Development Web Development ] [Code Generators Code Generators ] [Resources Resources ] [Contact Us Contact ] |WebDevTips Privacy Privacy |
Print This Page

You are here : Home - Web Development - Includes - Date & Time

Date & Time



alfie sets the time

There are several ways of putting the current date and time onto a webpage. Putting the the date and time on a webpage just for the sake of it can be pretty pointless but when used in the right context can add value.

Here are a few examples. There is a table of date and time formatting switches at the end.


The current local time :
<!--#echo var="DATE_LOCAL" -->
displays : Thursday, 18-Apr-2024 19:59:04 BST
 
The current time (GMT) :
<!--#echo var="DATE_GMT" -->
displays : Thursday, 18-Apr-2024 18:59:04 GMT
 
The current time (dd/mm/yy) :
<!--#config timefmt="%d/%m/%y" -->
<!--#echo var="DATE_LOCAL" -->

displays : 18/04/24
 
The current time (Day dd Month yyyy) :
<!--#config timefmt="%a %d %h %Y" -->
<!--#echo var="DATE_LOCAL" -->

displays : Thu 18 Apr 2024
 

As you can see from the small examples above, there are lots of ways to configure the output of you date. Using any combination of codes in the <!--#config timefmt="CODES" --> line you can pretty much format the output anyway you wish.

code Description
 %a  abbreviated weekday name
 %A  full weekday name
 %b  abbreviated month name
 %B  full month name
 %c  locale's appropriate date and time
 %C  default date and time format
 %d  day of month - 01 to 31
 %D  date as %m/%d/%y
 %e  day of month - 1 to 31
 %h  abbreviated month name (alias for %b)
 %H  hour - 00 to 23
 %I  hour - 01 to 12
 %j  day of year - 001 to 366
 %m  month of year - 01 to 12
 %M  minute - 00 to 59
 %n  insert a new line character
 %p  string containing AM or PM
 %r  time as %I:%M:%S %p
 %R  time as %H:%M
 %S  second - 00 to 61
 %t  insert a tab character
 %T  time as %H:%M:%S
 %U  week number of year - 00 to 53
 %w  day of week - Sunday=0
 %W  week number of year - 00 to 53
 %x  Country-specific date format
 %X  Country-specific time format
 %y  2 digit year - YY
 %Y  4 digit year - YYYY
 %Z  timezone name







Google
 

[back to top of page]   

[labelled with icra -  - this link will open in a new window] [RSS Content]

[Copyright © WebDevTips]