-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpletimestamphelper.html
executable file
·149 lines (134 loc) · 4.75 KB
/
simpletimestamphelper.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>Simple Timestamp Helper</title>
<script>
<!--
function getDateFromTimestamp(ts) {
var date = 0;
if(ts > 99999999999) {
date = new Date(parseInt(ts));
} else {
date = new Date(parseInt(ts * 1000));
}
document.getElementById('outputDate').innerHTML = date.toString();
}
function getTimestampFromDate(dt, type) {
var ts = Date.parse(dt);
document.getElementById('outputTimestampUnix' + type).innerHTML = parseInt(ts/1000);
document.getElementById('outputTimestampJava' + type).innerHTML = ts;
}
window.onload = function(e) {
//set current dates
document.getElementById('nowString').innerHTML = new Date().toString();
document.getElementById('nowLocaleString').innerHTML = new Date().toLocaleString();
document.getElementById('nowUTCString').innerHTML = new Date().toUTCString();
document.getElementById('nowJSON').innerHTML = new Date().toJSON();
document.getElementById('nowTimestampUnix').innerHTML = parseInt(new Date().getTime()/1000);
document.getElementById('nowTimestampJava').innerHTML = new Date().getTime();
//set intial date in datetime picker
var currentDate = new Date().toJSON().replace(/\..+/,'');
document.getElementById('dt_selection').value = currentDate;
getTimestampFromDate(currentDate, 'Selection');
}
-->
</script>
<style>
<!--
body {
font-family:sans-serif;
font-size:10pt;
}
div.outer_box {
padding:0px;
margin:5px 5px 15px 5px;
background-color:#c9d8dc;
width:400px;
}
div.inner_box {
padding-left:5px;
padding-bottom:5px;
margin:0px;
}
h1 {
color:#d9e8ec;
background-color:#1b4654;
padding:4px;
margin:0px;
font-size:12pt;
font-weight:bold;
}
p.description {
margin:2px 0px 2px 0px;
}
.padding_top {
padding-top:10px;
}
.curved_borders_top {
border-top-right-radius: 10px 10px;
border-top-left-radius: 10px 10px;
}
.curved_borders_bottom {
border-bottom-right-radius: 10px 10px;
border-bottom-left-radius: 10px 10px;
}
-->
</style>
</head>
<body>
<div class="outer_box curved_borders_top curved_borders_bottom">
<h1 class="curved_borders_top">Current Date</h1>
<div class="inner_box">
<table>
<tr><td colspan="2"><p class="description">Date Formats:</p></td></tr>
<tr><td>String: </td> <td id="nowString"></td></tr>
<tr><td>Locale String: </td><td id="nowLocaleString"></td></tr>
<tr><td>UTC String: </td> <td id="nowUTCString"></td></tr>
<tr><td>JSON: </td> <td id="nowJSON"></td></tr>
<tr><td colspan="2"><p class="description padding_top">Timestamps:</p></td></tr>
<tr><td>Unix: </td><td id="nowTimestampUnix"></td></tr>
<tr><td>Java: </td><td id="nowTimestampJava"></td></tr>
</table>
</div>
</div>
<div class="outer_box curved_borders_top curved_borders_bottom">
<h1 class="curved_borders_top">Timestamp to Date</h1>
<div class="inner_box">
<p class="description">Paste or type a timestamp here:</p>
<form>
<input id="ts" type="number" pattern="\d+" oninput="getDateFromTimestamp(this.value);" onpaste="getDateFromTimestamp(this.value);">
<input type="reset">
</form>
<p class="description">Date: <span id="outputDate"> </span></p>
</div>
</div>
<div class="outer_box curved_borders_top curved_borders_bottom">
<h1 class="curved_borders_top">Date to Timestamp by Paste</h1>
<div class="inner_box">
<p class="description">Paste or type a date string here:</p>
<form>
<input id="dt_paste" type="text" oninput="getTimestampFromDate(this.value, 'Paste');" onpaste="getTimestampFromDate(this.value, 'Paste');">
<input type="reset">
</form>
<table>
<tr><td>Unix Timestamp: </td><td><span id="outputTimestampUnixPaste"></span></td></tr>
<tr><td>Java Timestamp: </td><td><span id="outputTimestampJavaPaste"></span></td></tr>
</table>
</div>
</div>
<div class="outer_box curved_borders_top curved_borders_bottom">
<h1 class="curved_borders_top">Date to Timestamp by Selection</h1>
<div class="inner_box">
<p class="description">Set a date here:</p>
<form>
<input id="dt_selection" type="datetime-local" oninput="getTimestampFromDate(this.value, 'Selection');" onpaste="getTimestampFromDate(this.value, 'Selection');">
</form>
<table>
<tr><td>Unix Timestamp: </td><td><span id="outputTimestampUnixSelection"></span></td></tr>
<tr><td>Java Timestamp: </td><td><span id="outputTimestampJavaSelection"></span></td></tr>
</table>
</div>
</div>
</body>
</html>