इसका समाधान जावास्क्रिप्ट है - यह क्लाइंट पर समय क्षेत्र सेटिंग्स तक पहुंच सकता है। दुर्भाग्य से यह केवल विशिष्ट समय के लिए समय क्षेत्र ऑफसेट (मिनटों में निर्दिष्ट) प्राप्त कर सकता है, समय क्षेत्र का नाम नहीं। तो सही समय क्षेत्र हम भी जानने की जरूरत इंगित करने के लिए करता है, तो डेलाइट बचत समय (डीएसटी) नियोजित किया जा रहा है - इस समाधान का ग्राहक के पक्ष हिस्सा है:
var now = new Date();
var later = new Date();
// Set time for how long the cookie should be saved
later.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
// Set cookie for the time zone offset in minutes
setCookie("time_zone_offset", now.getTimezoneOffset(), later, "/");
// Create two new dates
var d1 = new Date();
var d2 = new Date();
// Date one is set to January 1st of this year
// Guaranteed not to be in DST for northern hemisphere,
// and guaranteed to be in DST for southern hemisphere
// (If DST exists on client PC)
d1.setDate(1);
d1.setMonth(1);
// Date two is set to July 1st of this year
// Guaranteed to be in DST for northern hemisphere,
// and guaranteed not to be in DST for southern hemisphere
// (If DST exists on client PC)
d2.setDate(1);
d2.setMonth(7);
// If time zone offsets match, no DST exists for this time zone
if(parseInt(d1.getTimezoneOffset())==parseInt(d2.getTimezoneOffset()))
{
setCookie("time_zone_dst", "0", later, "/");
}
// DST exists for this time zone – check if it is currently active
else {
// Find out if we are on northern or southern hemisphere
// Hemisphere is positive for northern, and negative for southern
var hemisphere = parseInt(d1.getTimezoneOffset())-parseInt(d2.getTimezoneOffset());
// Current date is still before or after DST, not containing DST
if((hemisphere>0 && parseInt(d1.getTimezoneOffset())==parseInt(now.getTimezoneOffset())) ||
(hemisphere<0 && parseInt(d2.getTimezoneOffset())==parseInt(now.getTimezoneOffset()))) { setCookie("time_zone_dst", "0", later, "/"); } // DST is active right now with the current date else { setCookie("time_zone_dst", "1", later, "/"); } }
आप कुकीज़ के रूप में परिणाम बचाने के लिए, जो हो सकता है आपकी PHP स्क्रिप्ट द्वारा एक्सेस किया गया। आपको उपर्युक्त कोड को कम से कम पहले पृष्ठ पर उपयोगकर्ता को शामिल करना चाहिए - इसमें प्रत्येक पृष्ठ पर परिवर्तनों को पहचानने और अनुकूलित करने के लिए शामिल किया गया है, भले ही सत्र के दौरान ऐसे परिवर्तन असंभव हैं।
PHP में आप PHP8.3 के बाद उपलब्ध टाइमज़ोन_नाम_from_abbr नामक एक नए फ़ंक्शन के साथ एक वैध समय क्षेत्र निकाल सकते हैं - यह या तो समय क्षेत्र संक्षेप या समय क्षेत्र ऑफ़सेट (सेकंड में) और डेलाइट सेविंग टाइम का संयोजन लेता है, - ध्यान दें कि उदाहरण के लिए कई "नकल" नाम हैं कि, "यूरोप
$time_zone_name = timezone_name_from_abbr(", -$_COOKIE['time_zone_offset']*60, $_COOKIE['time_zone_dst']);
यह आपको, उपयोगकर्ता के लिए एक सही समय क्षेत्र का नाम दे देंगे अगर कुकीज़ में डेटा मान्य है: और हम बाद के संयोजन है/बर्लिन "और" यूरोप/ज़्यूरिख ", जिनके पास सटीक समय क्षेत्र सेटिंग्स (कम से कम अभी के लिए) हैं, और आप उनमें से एक को उचित ऑफसेट और डीएसटी चर के लिए प्राप्त कर सकते हैं। समय क्षेत्र नामों की सूची php.net पर समर्थित समय क्षेत्र की सूची में पाई जा सकती है।
किसी दिए गए समय क्षेत्र उपयोगकर्ता के समय क्षेत्र अब आप अंत में सही समय क्षेत्र के साथ तारीख तार बनाने के लिए PHP वर्गों DateTimeZone और दिनांक समय उपयोग कर सकते हैं के नाम के साथ साथ तिथि तार बनाना:
// Create time zone class
$time_zone_class = new DateTimeZone($time_zone_name);
// Create new date class with a given date
// Notice that the provided date will be regarded as being in the
// default time zone and converted accordingly
$new_date = new DateTime(‘2007-02-14 15:30:00′, $time_zone_class);
// Print date with the user’s time zone echo $new_date->format(‘Y-m-d H:i:s’);
यही वह है!
स्रोत: http://togl.me/eE2
आप एक ajax कॉल के बाद पृष्ठ के लोड होते माध्यम से उलटी गिनती टाइमर ईंधन भरने के बारे में क्या सोचते हैं, आप शुरू में प्रदर्शित नहीं कर सका इसे छुपाकर काउंटर, फिर AJAX सफलता पर प्रदर्शित करें। अनुरोध बहुत तेज होगा क्योंकि आप एक पूर्ण पृष्ठ पोस्ट वापस नहीं कर रहे हैं। –