Closed NamalSanjaya closed 9 months ago
Ask location info from brower
// Check if the browser supports Geolocation
if (navigator.geolocation) {
// Request the current position
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
} else {
console.log("Geolocation is not supported by this browser.");
}
// Success callback function
function successCallback(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
console.log("Latitude: " + latitude);
console.log("Longitude: " + longitude);
// Make use of latitude and longitude to get the location information using external APIs or services
}
// Error callback function
function errorCallback(error) {
console.log("Error getting location: " + error.message);
}
How to get time based on the location
// Create a new Date object
var date = new Date();
// Get the current date and time in Sri Lankan format
var options = { timeZone: 'Asia/Colombo', hour12: false };
var sriLankanDateTime = date.toLocaleString('en-LK', options);
var utcTime = date.toLocaleString('en-US', { timeZone: 'UTC' });
console.log(sriLankanDateTime, utcTime);
Once this problem solved, we need to change all places in our nexster project related to time.
In backend we use UTC time zone with no offset. which means our all the time related information store in database store for UTC-0.
Therefore all outgoing API request need to have additional data to figure out the offset of respective location.
front end and back end usually run on different places. There fore they have different time values. In distributed systems even in multiple back-end systems they have different time values. This issue need a long term solution. Here are few suggestions