This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I need to get this data to send in a HTTP header. Is there any direct function to do this. I'm guessing I could do it myself using OS.get_datetime but that may not return whether this is GMT or not. The header data must look like this:

Fri, 08 Apr 2015 03:52:31 GMT

Thanks

in Engine by (298 points)

1 Answer

+1 vote
Best answer

You can build it from OS.get_datetime:

var time = OS.get_datetime()
var nameweekday= ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
var namemonth= ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
var dayofweek = time["weekday"]   # from 0 to 6 --> Sunday to Saturday
var day = time["day"]                         #   1-31
var month= time["month"]               #   1-12
var year= time["year"]             
var hour= time["hour"]                     #   0-23
var minute= time["minute"]             #   0-59
var second= time["second"]             #   0-59

var dateRFC1123 = str(nameweekday[dayofweek]) + ", " + str("%02d" % [day]) + " " + str(namemonth[month-1]) + " " + str(year) + " " + str("%02d" % [hour]) + ":" + str("%02d" % [minute]) + ":" + str("%02d" % [second]) + " GMT"
by (1,488 points)
selected by

you can simply do it with this too.

var dateRFC1123 = "%s, %02d %s %d %02d:%02d:%02d GMT" % [nameweekday[dayofweek], day, namemonth[month-1], year, hour, minute, second]
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.