vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Timestamp to date with userdefined timezone? (https://vborg.vbsupport.ru/showthread.php?t=192104)

Cip 09-28-2008 07:05 AM

Timestamp to date with userdefined timezone?
 
I have several custom pages in vBulletin currently presenting dates from timestamps by using the date() function in PHP. But this is very inconvenient for some of my users as I'm currently only displaying the dates and times according to my own timezone.

I tried to come up with a solution but it proved to be rather flawed..
Here's what I did:
PHP Code:

$timestamp $character->getAttr('lastlogout');

//If the timezoneoffset field in vb_user table contains a -
if (ereg("^\-)$",$vbulletin->userinfo['timezoneoffset'])){

    
//Besides from substracting the timezoneoffset we also substract 1 hour because I'm GMT+1
    
$timezoneoffset date("G"$timestamp).$vbulletin->userinfo['timezoneoffset']-1;
}else{

    
//No -, lets sum it instead, but still remove 1 hour because I'm GMT+1
    
$timezoneoffset date("G"$timestamp)+$vbulletin->userinfo['timezoneoffset']-1;
}

//Generate date string from a timestamp with the appropriate changes to the timezone
$lastlogin date("M j, G:i Y"mktime($timezoneoffsetdate("i"$timestamp), 0date("m"$timestamp), date("d"$timestamp),   date("Y"$timestamp))); 

Now here's the catch. I haven't found a way to see wether a member has DST turned on, so the Last Login field has a tendency to jump ahead (or maybe it was backwards :o) an hour.

Is there an easier way to do this? Or at least to find out the DST settings?

Marco van Herwaarden 09-28-2008 10:14 AM

If you are including global.php in your custom pages, then you can use the vbdate
function.

Cip 09-28-2008 10:28 PM

Awesome, thanks :D


All times are GMT. The time now is 07:18 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01107 seconds
  • Memory Usage 1,722KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete