Jump to content

get the GMT time


Desaster

Recommended Posts

I've done some research for you, and I found that the best way to achieve this would to use a public API. I was thinking of using it with a Unix timestamp of the local computers time to find a near accurate timezone, or we could use an ip address, or we could use both to get a more accurate GMT result.

I have found the best API for this job, I have used them before with old projects. You will need to register an account and recieve your API key first:

1) Getting an API key from IPInfoDB

A) Goto http://ipinfodb.com/register.php

B) Fill in the details on the register page and click register.

C) You will need to go to your email to confirm your account.

D) When you log-in you will now see your API Key at the bottom of the grey box, keep that somewhere, we will need it shortly.

EXAMPLE: API Key aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

addEventHandler('onPlayerJoin', root, 
function() 
    -- Trigger GMT request 
    local theIP = getPlayerIP(source) 
    local theKey = 'MYKEYHERE' 
    local apiURL = 'http://api.ipinfodb.com/v3/ip-city/?key='..theKey..'&ip='..theIP..'&format=json' 
     
    fetchRemote(apiURL, gmtData, "", false, source) 
end ) 
  
function gmtData(data, response, player) 
    local data = '['..data..']' 
    local theData = fromJSON(data) 
    if theData then 
        setElementData(player, 'timezone', theData['timeZone']) 
    else 
        outputDebugString('Error parsing data') 
    end 
end 

^^ Tested and works, make sure you put your API key in it. To read it just use getElementData.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...