5
Contributors
19
Replies
73
Views
3 Years
Discussion Span
Last Post by diafol
Featured Replies
  • 2
    diafol 3,669   3 Years Ago

    php and mysql work pff their servers. they dont use the user's machine time. you can set the display to the timezone of the user's choice via settings i their profile if you've given them one. Read More

  • 1

    There is function in PHP called date_default_timezone_set() which can set the default time zone of an application or the runtime configuration. For example, we can define the default timezone of an application to any timezone supported. date_default_timezone_set('Europe/London'); if we do this echo time(); Will give us the timestamp for London. … Read More

  • 1

    can you try running this <?php phpinfo(); direct your browser to this page and look for the loaded configuration file. It should tell you which php.ini is being loaded by the xampp. Read More

  • 2
    diafol 3,669   3 Years Ago

    You are running this on a local server right? So if you change the local machine system time, you will change the server time. When running on a remote system, you will be on 'their' server time, which will not be under your or anybody else's control, other than your … Read More

  • 2
    diafol 3,669   3 Years Ago

    A PMS will store messages in a DB, usually with a timestamp (unix flavoured) or sometimes with a datetime. Timestamp is favoured as this makes it easier to provide users with displayed datetimes conforming to their timezones - but only if you give them the ability to set their timezones, … Read More

0

You would need to connect to an external timeserver or use a third party app that connects to a time server. PHP only knows the time for the box it is on

0

You would need to connect to an external timeserver or use a third party app that connects to a time server. PHP only knows the time for the box it is on

and how should i do that?
Thanks

-1

It depends on what you want as a source of truth for time. Using an alternate time source isn't a trivial problem. An easier approach that I would recommend, and use myself, is to keep the server/computer time synced and then just use the server/computer time inside of PHP.

Unfortunately, I don't know of any specific time servers or time applications to recommend

0

Dont know what u meant by "sync" but what are u suggesting is that i keep my computer time right so the fuction display the right time?

What im trying to do is a private message system But what about those who has other times on ther computers? It will get pretty ugly if the message says sent at 11:25/2005 if there computers time is messed up
Thanks for reply

2

php and mysql work pff their servers. they dont use the user's machine time. you can set the display to the timezone of the user's choice via settings i their profile if you've given them one.

0

php and mysql work pff their servers. they dont use the user's machine time. you can set the display to the timezone of the user's choice via settings i their profile if you've given them one.

I have a timezone set in php.ini, but still when i change the time on my pc the time change, then how can i fix this?

1

There is function in PHP called date_default_timezone_set() which can set the default time zone of an application or the runtime configuration.

For example, we can define the default timezone of an application to any timezone supported.

date_default_timezone_set('Europe/London');

if we do this

echo time();

Will give us the timestamp for London. I am not sure if the time is adjusted to DST. If not, then the timestamp will be an hour late to the actual time.

If you have access to php.ini file and if you are allowed to edit it, you can add or define the date.timezone to whatever timezone you want as long as it is supported.

date.timezone = "Europe/London"

Please read this list of supported timezones.

Update:
For mysql, please refer to this documentation.

Edited by veedeoo: more info. added

0

There is function in PHP called date_default_timezone_set() which can set the default time zone of an application or the runtime configuration.

I have a date.timezone set already it still change the time when i change my pc's time :/

Thanks

0

php and mysql work pff their servers. they dont use the user's machine time. you can set the display to the timezone of the user's choice via settings i their profile if you've given them one.

The first picture i took the screeshot minutes later that why shows a different time

2b233e439281846f62525ab527930f68187e011cf7747be9c8942845f6f9d0c3

Edited by centenond

1

can you try running this

<?php

     phpinfo();

direct your browser to this page and look for the loaded configuration file. It should tell you which php.ini is being loaded by the xampp.

2

You are running this on a local server right? So if you change the local machine system time, you will change the server time. When running on a remote system, you will be on 'their' server time, which will not be under your or anybody else's control, other than your host. This is a separate issue to the uses of timezones.

-1

Ah, a chat system. If you are using a single server(the most likely scenario), then you use that server's time.

You then make a client that each user would use to connect to the server. (a browser page for example) Any message must first be sent to the server, and then the server send it to the client (and a confirmation back to the original sender for their timestamp. The clients can then set the local time zone however you want to let them.

Another option is to not use a server and let each client set the time stamp for when it displays the message. The only potential drawback, is that two separate clients might have different timestamps for the same conversation. This is the easier approach.

One thing to note for a client application - unless run through browser requests, PHP is not a wonderful for installing on client boxes.

Added note: I think this was described, but you could also request the current time from a SQL server.

Edited by Kyle Wiering: sql server note

2

A PMS will store messages in a DB, usually with a timestamp (unix flavoured) or sometimes with a datetime. Timestamp is favoured as this makes it easier to provide users with displayed datetimes conforming to their timezones - but only if you give them the ability to set their timezones, e.g. in a users table.

e.g.

user_id
username
passhash
...
datetime_format ("d/m/Y h:i:s a")
timezone ("Europe/London")

This can then be used when perusing the site, e.g. the PMS...

date_default_timezone_set($userTZ);
//...
echo date($userDtFormat,$msg['timestamp']);
-1

In the end, there are a lot of suggested approaches. A db is a heavy handed solution, imo, but it would also work. Regardless, I think the original question has been answered quite thoroughly.

0

You are running this on a local server right? So if you change the local machine system time, you will change the server time. When running on a remote system, you will be on 'their' server time, which will not be under your or anybody else's control, other than your host. This is a separate issue to the uses of timezones

I figuered this out yesturday cuz i tried it in ipage and it worked fine :3 so my guess was what u say, Many many thanks!

0

@centenond I am having a same issue. Please let me know how did you figured out this problem

0

You set the timezone of your choice in your pages - for display purposes:

date_default_timezone_set($userTZ);

Be careful if storing datetime format - ensure that you use YOUR choice of TZ, not user. Storing - it's safer to use timestamp (integer).

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.