Jump to content

date()


shadowayex

Recommended Posts

I use the date() function to get the time and date of messages sent through my messaging system on my site. How would I have the time and date altered to match certain time zones depending on where the user lives?

Link to comment
Share on other sites

EDITED POST:I took a look and this is what I came up with. I want to use gmdate(U) to get the number of seconds since the Unix Epoch, then subtract seconds that correspond to the timezone difference from GMT. I have that figured out fine. Now, I want to convert this into a format that goes like this:Hour:Minute of Month Day, YearIs there a way?

Link to comment
Share on other sites

Ok I tried every idea I could think of. Can just ell me how to get a date, edit it by timezone, and make sure the AM/PM switches if need be (i.e. 12:30 PM Central Time to 10:30 AM Pacific Time) and the date switches if need be (i.e. 12:30 AM Central Time on the 25th to 10:30 PM Pacific Time on the 24th). I'd do it myself, but evidently there's something I'm not finding or understanding because no matter what, if I do manage to get the time to even edit, it always ends up a timestamp and I don't know how to convert timestamps into a real freaking display of a time and date (Sorry but I'm getting extremely annoyed at this point because I'm trying so hard to get something going for this website for my friends and my girlfriend and it's not working).

Link to comment
Share on other sites

I'm not sure what you're looking at, but the date function doesn't return a timestamp. Did you look at the examples on the page?

<?php// set the default timezone to use. Available since PHP 5.1date_default_timezone_set('UTC');// Prints something like: Mondayecho date("l");// Prints something like: Monday 8th of August 2005 03:12:46 PMecho date('l jS \of F Y h:i:s A');// Prints: July 1, 2000 is on a Saturdayecho "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));/* use the constants in the format parameter */// prints something like: Mon, 15 Aug 2005 15:12:46 UTCecho date(DATE_RFC822);// prints something like: 2000-07-01T00:00:00+00:00echo date(DATE_ATOM, mktime(0, 0, 0, 7, 1, 2000));?><?php// Assuming today is: March 10th, 2001, 5:16:18 pm$today = date("F j, Y, g:i a");				 // March 10, 2001, 5:16 pm$today = date("m.d.y");						 // 03.10.01$today = date("j, n, Y");					   // 10, 3, 2001$today = date("Ymd");						   // 20010310$today = date('h-i-s, j-m-y, it is w Day z ');  // 05-16-17, 10-03-01, 1631 1618 6 Fripm01$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day.$today = date("D M j G:i:s T Y");			   // Sat Mar 10 15:16:08 MST 2001$today = date('H:m:s \m \i\s\ \m\o\n\t\h');	 // 17:03:17 m is month$today = date("H:i:s");						 // 17:16:17?>

Link to comment
Share on other sites

The date() gets the date just fine, but I can't modify the time with date_modify(). The only way to modify the time is use stroftime(), which converts it into a time stamp. From there, I can't convert back, that I know of. If I could, I'd do everything in timestamps and convert at the end.

Link to comment
Share on other sites

This isn't really a PHP problem, but I figured people here would know. I've got my time zone adjusting to work, and I'm trying to implement a tool that will fix the Daylight Savings Time changes. I have a list of time zones here and I need to know which time zones are affected by daylight savings time and when it goes into effect and comes out of effect. I tried googling it and just got pages and pages of "DST Changes in 2007," which is annoying.

Link to comment
Share on other sites

>_< I think I'll just add an option to the account page letting users set daylight savings time themselves, for now. Until I get more of an overview what areas are actually using the site. Because it seems like a lot of work to try and track down whether the user lives in an area that uses DST or not. Thanks for the help anyways. I'm saving the site for possible future system.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...