これをコードに追加すると
$today1 = date("d");
ユーザーのローカルシステムの日付ではなく、サーバーの日付が表示されます。
使いたくないdate_default_timezone_set()
PHPを使用して、その時点でローカルユーザー(Webホストサーバーではない)の日付を取得するにはどうすればよいですか。
これをコードに追加すると
$today1 = date("d");
ユーザーのローカルシステムの日付ではなく、サーバーの日付が表示されます。
使いたくないdate_default_timezone_set()
PHPを使用して、その時点でローカルユーザー(Webホストサーバーではない)の日付を取得するにはどうすればよいですか。
デフォルトのタイムゾーン関数でない限り、それを行うことはできません。PHPはクライアントサイドではなくサーバーサイドです。そのためにjavascriptを使用する必要があるかもしれません-
var now = new Date();
now.format("m/dd/yy");
// Returns, e.g., 6/09/07
// Can also be used as a standalone function
dateFormat(now, "dddd, mmmm dS, yyyy, h:MM:ss TT");
// Saturday, June 9th, 2007, 5:46:21 PM
// You can use one of several named masks
now.format("isoDateTime");
// 2007-06-09T17:46:21
// ...Or add your own
dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
now.format("hammerTime");
// 17:46! Can't touch this!
// When using the standalone dateFormat function,
// you can also provide the date as a string
dateFormat("Jun 9 2007", "fullDate");
// Saturday, June 9, 2007
// Note that if you don't include the mask argument,
// dateFormat.masks.default is used
now.format();
// Sat Jun 09 2007 17:46:21
// And if you don't include the date argument,
// the current date and time is used
dateFormat();
// Sat Jun 09 2007 17:46:22
// You can also skip the date argument (as long as your mask doesn't
// contain any numbers), in which case the current date/time is used
dateFormat("longTime");
// 5:46:22 PM EST
// And finally, you can convert local time to UTC time. Either pass in
// true as an additional argument (no argument skipping allowed in this case):
dateFormat(now, "longTime", true);
now.format("longTime", true);
// Both lines return, e.g., 10:46:21 PM UTC
// ...Or add the prefix "UTC:" to your mask.
now.format("UTC:h:MM:ss TT Z");
// 10:46:21 PM UTC
またはこれを試してください - https://bitbucket.org/pellepim/jstimezonedetect
AJAX を使用して、日時の値を PHP ファイルに送信するだけです。簡単で、そのためにjQueryを使用できます。次に、Cookie/セッションを設定します。それでおしまい!