0 votes

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

asked Oct 23, 2017 in Engine by stubbsy345 (282 points)

1 Answer

0 votes
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"
answered Oct 24, 2017 by jospic (1,444 points)
selected Oct 24, 2017 by stubbsy345

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 How to use this Q&A? before posting your first questions.