Created
May 28, 2013 06:35
-
-
Save mlf4aiur/5660850 to your computer and use it in GitHub Desktop.
Convert http date to unix timestamp AWK function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function httpdate2unixtimestamp(date, array, time_string, timestamp) { | |
| # input: [02/Dec/2011:04:02:42 -0500] | |
| # output: 1322816562 | |
| # date is argument | |
| # array, time_string, timestamp is local variable | |
| split(date, array, "[]/: []") | |
| if (array[3]=="Jan") month="01" | |
| else if (array[3]=="Feb") month="02" | |
| else if (array[3]=="Mar") month="03" | |
| else if (array[3]=="Apr") month="04" | |
| else if (array[3]=="May") month="05" | |
| else if (array[3]=="Jun") month="06" | |
| else if (array[3]=="Jul") month="07" | |
| else if (array[3]=="Aug") month="08" | |
| else if (array[3]=="Sep") month="09" | |
| else if (array[3]=="Oct") month="10" | |
| else if (array[3]=="Nov") month="11" | |
| else if (array[3]=="Dec") month="12" | |
| # YYYY MM DD HH MM SS[ DST] | |
| time_string=array[4]" "month" "array[2]" "array[5]" "array[6]" "array[7]" "array[8] / 100 | |
| timestamp=mktime(time_string) | |
| return timestamp | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment