I would like to display current date and time, what would be the best way to do this in drupal 7? I would like to display either the local time pst or the users that is visiting their local time. These would be anonymous visitors.
Thanks.
Follow me on: Twitter: http://twitter.com/1rubytweets Facebook: http://www.facebook.com/profile.php?id=1058306793 Join me on: Yahoo: jruby6767 Msn: jruby@charter.net
Hey Jim,
If you want it hard coded into the site add this line to your page.tpl.php for your theme:
<?php print date('l, F j, Y g:i a T') ?>
This will print the date time like: Sunday September 18, 2011 5:15 am EST. If you want to tweek the way the time and date display, go to http://us.php.net/manual/en/function.date.php for a list of date / time parts and examples. So you can theme the date and time, you can wrap this in html tags like so:
<div id="myTimeAndDate" class="myTimeAndDate"> <?php print date('l, F j, Y g:i a T') ?> </div>
Hope this helps, Cory
On Mon, Sep 19, 2011 at 6:30 PM, Jim Ruby jim@v-community.com wrote:
I would like to display current date and time, what would be the best way to do this in drupal 7? I would like to display either the local time pst or the users that is visiting their local time. These would be anonymous visitors.
Thanks.
Follow me on: Twitter: http://twitter.com/1rubytweets Facebook: http://www.facebook.com/profile.php?id=1058306793 Join me on: Yahoo: jruby6767 Msn: jruby@charter.net
-- [ Drupal support list | http://lists.drupal.org/ ]
There are two problems with this approach.
Firstly, date() does not account for user timezones. You could use Drupal's format_date() function instead. It works similarly. http://api.drupal.org/api/drupal/includes--common.inc/function/format_date
Secondly, this is incompatible with caching. You could use JavaScript to get around this problem. On a somewhat related note, you can also use JavaScript to show relative date information, similar to this approach http://37signals.com/svn/posts/1557-javascript-makes-relative-times-compatib... this example, I'd recommend using HTML 5 data attributes. See http://ejohn.org/blog/html-5-data-attributes/ for more information.)
Carl Wiedemann Website design and development consulting carl.wiedemann@gmail.com | skype: c4rlww
On Mon, Sep 19, 2011 at 9:19 PM, Cory Gilliam imaaxa@gmail.com wrote:
Hey Jim,
If you want it hard coded into the site add this line to your page.tpl.php for your theme:
<?php print date('l, F j, Y g:i a T') ?>
This will print the date time like: Sunday September 18, 2011 5:15 am EST. If you want to tweek the way the time and date display, go to http://us.php.net/manual/en/function.date.php for a list of date / time parts and examples. So you can theme the date and time, you can wrap this in html tags like so:
<div id="myTimeAndDate" class="myTimeAndDate"> <?php print date('l, F j, Y g:i a T') ?> </div>
Hope this helps, Cory
On Mon, Sep 19, 2011 at 6:30 PM, Jim Ruby jim@v-community.com wrote:
I would like to display current date and time, what would be the best way to do this in drupal 7? I would like to display either the local time pst or the users that is visiting their local time. These would be anonymous visitors.
Thanks.
Follow me on: Twitter: http://twitter.com/1rubytweets Facebook: http://www.facebook.com/profile.php?id=1058306793 Join me on: Yahoo: jruby6767 Msn: jruby@charter.net
-- [ Drupal support list | http://lists.drupal.org/ ]
-- Cory Gilliam Knoxville, TN 37921 imaaxa@gmail.com 865.335.3250
-- [ Drupal support list | http://lists.drupal.org/ ]
On Mon, Sep 19, 2011 at 11:30 PM, Jim Ruby jim@v-community.com wrote:
I would like to display current date and time, what would be the best way to do this in drupal 7?
The date module is helpful and it also has an API.