├── CNAME ├── icons ├── 16.png └── 32.png ├── .editorconfig ├── .gitignore ├── README.md ├── LICENSE ├── main.js ├── styles.css └── index.html /CNAME: -------------------------------------------------------------------------------- 1 | godatetime.com -------------------------------------------------------------------------------- /icons/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vimux/godatetime/master/icons/16.png -------------------------------------------------------------------------------- /icons/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vimux/godatetime/master/icons/32.png -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Node/npm 2 | node_modules/ 3 | npm-debug.log 4 | 5 | # IDE 6 | .idea 7 | *.sublime-project 8 | *.sublime-workspace 9 | .vscode/* 10 | 11 | # OS 12 | ._* 13 | Thumbs.db 14 | .DS_Store 15 | .Trashes 16 | .Spotlight-V100 17 | .AppleDouble 18 | .LSOverride 19 | Desktop.ini 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # strftime to Go Date Format Converter 2 | 3 | Simple strftime to Go Date Format Converter. 4 | 5 | ## Why? 6 | 7 | Because I've used `strftime` a million times before. 8 | 9 | ## License 10 | 11 | Original code & idea inherited from [another repository](https://github.com/bdotdub/fuckinggodateformat). 12 | 13 | Code released under the [MIT License](https://github.com/vimux/godatetime/blob/master/LICENSE). 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Vimux 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | document.addEventListener('DOMContentLoaded', function(){ 2 | let mapping = { 3 | "%a": "Mon", 4 | "%A": "Monday", 5 | "%b": "Jan", 6 | "%B": "January", 7 | "%d": "02", 8 | "%e": "_2", 9 | "%m": "01", 10 | "%y": "06", 11 | "%Y": "2006", 12 | "%H": "15", 13 | "%I": "03", 14 | "%l": "3", 15 | "%M": "04", 16 | "%P": "pm", 17 | "%p": "PM", 18 | "%S": "05", 19 | "%Z": "MST", 20 | "%z": "-0700", 21 | "%%": "%", 22 | 23 | // Go doesn't support that strftime codes 24 | "%j": "%j", 25 | "%U": "%U", 26 | "%W": "%W", 27 | "%w": "%w", 28 | "%x": "%x", 29 | "%X": "%X", 30 | "%c": "%c" 31 | } 32 | 33 | function strftime(str) { 34 | let res = ""; 35 | for (let i = 0; i < str.length; i++) { 36 | let f = mapping[str.substr(i, 2)]; 37 | if (f) { 38 | res += f; 39 | i++; 40 | } else { 41 | res += str[i]; 42 | } 43 | } 44 | 45 | return res; 46 | } 47 | 48 | function update(cb) { 49 | let input = document.querySelector("#strftime").value; 50 | let output = strftime(input); 51 | document.querySelector("#output").value = output; 52 | 53 | if (cb) { 54 | cb(); 55 | } 56 | } 57 | 58 | function appendCode() { 59 | let inputEl = document.querySelector("#strftime"); 60 | let code = this.textContent; 61 | 62 | document.querySelector("#strftime").value = document.querySelector("#strftime").value + " " + code; 63 | 64 | let event = document.createEvent("HTMLEvents"); 65 | event.initEvent("update", true, false); 66 | inputEl.dispatchEvent(event); 67 | } 68 | 69 | function highlight() { 70 | this.setSelectionRange(0, this.value.length); 71 | } 72 | 73 | document.querySelector("#strftime").addEventListener("keyup", update); 74 | document.querySelector("#strftime").addEventListener("update", update); 75 | document.querySelector("#output").addEventListener("click", highlight); 76 | 77 | definitions = document.querySelector("#definitions").querySelectorAll(".definition__name"); 78 | for(let i = 0; i 2 | 3 | 4 | 5 | 6 | 7 | strftime to Go Date Format Converter | godatetime.com 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |

Go Date Format

16 |

Because I've used strftime a million times before

17 |
18 | 19 |
20 |
21 |
22 | 23 |
24 |
25 |
26 | 27 |
28 |
29 | 30 |
31 |
32 |
33 |
%a
34 |
The abbreviated weekday name ("Sun")
35 |
%A
36 |
The full weekday name ("Sunday")
37 |
%b
38 |
The abbreviated month name ("Jan")
39 |
%B
40 |
The full month name ("January")
41 |
%d
42 |
Day of the month (01..31)
43 |
%e
44 |
Day of the month with a leading blank instead of zero ( 1..31)
45 |
%m
46 |
Month of the year (01..12)
47 |
%y
48 |
Year without a century (00..99)
49 |
%Y
50 |
Year with century
51 |
52 |
53 |
54 |
55 |
%H
56 |
Hour of the day, 24-hour clock (00..23)
57 |
%I
58 |
Hour of the day, 12-hour clock (01..12)
59 |
%l
60 |
Hour of the day, 12-hour clock without a leading zero (1..12)
61 |
%M
62 |
Minute of the hour (00..59)
63 |
%P
64 |
Meridian indicator ("am" or "pm")
65 |
%p
66 |
Meridian indicator ("AM" or "PM")
67 |
%S
68 |
Second of the minute (00..60)
69 |
%z
70 |
Time zone hour and minute offset from UTC
71 |
%Z
72 |
Time zone name
73 |
%%
74 |
Literal "%" character
75 |
76 |
77 |
78 | 79 |
80 |

Codes not natively supported in Go

81 |
82 |
83 |
%j
84 |
Day of the year (001..366)
use YearDay() instead
85 |
%U
86 |
Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
87 |
%W
88 |
Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
use ISOWeek() instead
89 |
%w
90 |
Day of the week (Sunday is 0, 0..6)
use Weekday() instead
91 |
92 |
93 |
94 |
95 |
%X
96 |
Preferred representation for the time alone, no date
97 |
%x
98 |
Preferred representation for the date alone, no time
99 |
%c
100 |
The preferred local date and time representation
101 |
102 |
103 |
104 |
105 | 106 | 110 | 111 | 112 | 113 | --------------------------------------------------------------------------------