Jump to content
Sign in to follow this  

Date/Time to UTC (HTTP RFC 2616) compatible format

Recommended Posts


I need some elegant way in Autoit for converting date/time to format compatible with RFC 2616 used in HTTP protocol/communication

Here are some references:



VB/C - ToUniversalTime http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime%28v=vs.71%29.aspx

The result should be something like this:

Fri Mar 30 2012 02:00:00 GMT+0200

Here are some scripts for this in other language:


new Date("2012-07-21 10:12:14").toUTCString()


gmstrftime("%a, %d %b %Y %T %Z", strtotime("2012-07-21 10:12:14"));


require 'time'
Time.parse('2012-07-21 10:12:14').httpdate


I need this for my Odorik.cz API project, see details here

Edited by Zedna

Share this post

Link to post
Share on other sites

A modified WinHTTP function may be a convenient start:

; #FUNCTION# ;===============================================================================
; Name...........: __WinHttpTimeFromSystemTime
; Description ...: Formats a system date and time according to the HTTP version 1.0 specification.
; Syntax.........: __WinHttpTimeFromSystemTime()
; Parameters ....: None.
; Return values .: Success - Returns 1.
;                         - Sets @error to 0
;                 Failure - Returns 0 and sets @error:
;                 |1 - Initial DllCall failed.
;                 |2 - Main DllCall failed.
; Author ........: trancexx
; Modified.......: jchd (changed GetSystemTime to GetLocalTime) TODO change output from "GMT" to correct time adjustment
; Remarks .......:
; Related .......:
; Link ..........; http://msdn.microsoft.com/en-us/library/aa384117(VS.85).aspx
; Example .......; Yes
Func _WinHttpTimeFromSystemTime()

    Local $SYSTEMTIME = DllStructCreate("ushort Year;" & _
            "ushort Month;" & _
            "ushort DayOfWeek;" & _
            "ushort Day;" & _
            "ushort Hour;" & _
            "ushort Minute;" & _
            "ushort Second;" & _
            "ushort Milliseconds")

    DllCall("kernel32.dll", "none", "GetLocalTime", "ptr", DllStructGetPtr($SYSTEMTIME))

    If @error Then
        Return SetError(1, 0, 0)

    Local $sTime = DllStructCreate("wchar[62]")

    Local $a_iCall = DllCall("winhttp.dll", "int", "WinHttpTimeFromSystemTime", _
            "ptr", DllStructGetPtr($SYSTEMTIME), _
            "ptr", DllStructGetPtr($sTime))

    If @error Or Not $a_iCall[0] Then
        Return SetError(2, 0, 0)

    Return SetError(0, 0, DllStructGetData($sTime, 1))

EndFunc   ;==>_WinHttpTimeFromSystemTime

MsgBox(64, "WinHttp time", _WinHttpTimeFromSystemTime())

but you will have to tweak the output (or use some internal black magic) as it doesn't seem to process the timezone and DST properly (at least on Vista x86.

I just get:

Fri, 06 Apr 2012 02:35:20 GMT

but that should have been:

Fri, 06 Apr 2012 02:35:20 +0200

(I'm in Paris TZ with DST on)

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post
Share on other sites

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
Sign in to follow this