Skip to content

Commit af6dca5

Browse files
committed
Format code
1 parent 1e60bb7 commit af6dca5

File tree

3 files changed

+107
-35
lines changed

3 files changed

+107
-35
lines changed

datetime-jsp/datetime.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
* {
22
font-family: system-ui;
33
}
4+
45
body {
56
line-height: 150%;
67
}

datetime-jsp/datetime.html

Lines changed: 100 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,104 @@
11
<html>
2-
3-
<head>
4-
<link rel="stylesheet" type="text/css" href="datetime.css">
2+
<head>
3+
<link rel="stylesheet" type="text/css" href="datetime.css" />
54
<title>Get date and time in all supported formats in Java</title>
65
<h1>Enter date and time values</h1>
7-
</head>
8-
9-
<body>
10-
<form method="post" action="datetime.jsp">
11-
<label for="year">Year:</label><br>
12-
<input type="number" name="year" id="year" required onchange="getDaysInMonth()"><br>
13-
<label for="month">Month:</label><br>
14-
<input type="number" name="month" id="month" min="1" max="12" required onchange="getDaysInMonth()"><br>
15-
<label for="day">Day:</label><br>
16-
<input type="number" name="day" id="day" min="1" max="31" required><br>
17-
<label for="hour">Hour:</label><br>
18-
<input type="number" name="hour" id="hour" min="0" max="23" required><br>
19-
<label for="minute">Minute:</label><br>
20-
<input type="number" name="minute" id="minute" min="0" max="59" required><br>
21-
<label for="second">Second:</label><br>
22-
<input type="number" name="second" id="second" min="0" max="59" required><br>
23-
<label for="millisecond">Millisecond:</label><br>
24-
<input type="number" name="millisecond" id="millisecond" min="0" max="999" required value="0"><br>
25-
<label for="microsecond">Microsecond:</label><br>
26-
<input type="number" name="microsecond" id="microsecond" min="0" max="999" required value="0"><br>
27-
<label for="nanosecond">Nanosecond:</label><br>
28-
<input type="number" name="nanosecond" id="nanosecond" min="0" max="999" required value="0"><br>
29-
<button type="button" onclick="setCurrentDate()">Set Current Local Date and Time</button>
30-
<button type="button" onclick="setCurrentUtcDate()">Set Current UTC Date and Time</button>
31-
<input type="submit" value="Submit">
32-
</form>
33-
<script src="datetime.js"></script>
34-
</body>
6+
</head>
357

36-
</html>
8+
<body>
9+
<form method="post" action="datetime.jsp">
10+
<label for="year">Year:</label><br />
11+
<input
12+
type="number"
13+
name="year"
14+
id="year"
15+
required
16+
onchange="getDaysInMonth()"
17+
/><br />
18+
<label for="month">Month:</label><br />
19+
<input
20+
type="number"
21+
name="month"
22+
id="month"
23+
min="1"
24+
max="12"
25+
required
26+
onchange="getDaysInMonth()"
27+
/><br />
28+
<label for="day">Day:</label><br />
29+
<input
30+
type="number"
31+
name="day"
32+
id="day"
33+
min="1"
34+
max="31"
35+
required
36+
/><br />
37+
<label for="hour">Hour:</label><br />
38+
<input
39+
type="number"
40+
name="hour"
41+
id="hour"
42+
min="0"
43+
max="23"
44+
required
45+
/><br />
46+
<label for="minute">Minute:</label><br />
47+
<input
48+
type="number"
49+
name="minute"
50+
id="minute"
51+
min="0"
52+
max="59"
53+
required
54+
/><br />
55+
<label for="second">Second:</label><br />
56+
<input
57+
type="number"
58+
name="second"
59+
id="second"
60+
min="0"
61+
max="59"
62+
required
63+
/><br />
64+
<label for="millisecond">Millisecond:</label><br />
65+
<input
66+
type="number"
67+
name="millisecond"
68+
id="millisecond"
69+
min="0"
70+
max="999"
71+
required
72+
value="0"
73+
/><br />
74+
<label for="microsecond">Microsecond:</label><br />
75+
<input
76+
type="number"
77+
name="microsecond"
78+
id="microsecond"
79+
min="0"
80+
max="999"
81+
required
82+
value="0"
83+
/><br />
84+
<label for="nanosecond">Nanosecond:</label><br />
85+
<input
86+
type="number"
87+
name="nanosecond"
88+
id="nanosecond"
89+
min="0"
90+
max="999"
91+
required
92+
value="0"
93+
/><br />
94+
<button type="button" onclick="setCurrentDate()">
95+
Set Current Local Date and Time
96+
</button>
97+
<button type="button" onclick="setCurrentUtcDate()">
98+
Set Current UTC Date and Time
99+
</button>
100+
<input type="submit" value="Submit" />
101+
</form>
102+
<script src="datetime.js"></script>
103+
</body>
104+
</html>

datetime-jsp/datetime.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ var second = document.querySelector("#second");
77
var millisecond = document.querySelector("#millisecond");
88
var microsecond = document.querySelector("#microsecond");
99
var nanosecond = document.querySelector("#nanosecond");
10+
1011
function setCurrentDate() {
1112
var currentDate = new Date();
1213
var currentYear = currentDate.getFullYear();
13-
var currentMonth = currentDate.getMonth() + 1;//Add 1 to month because 0 is January in JavaScript and 1 in Java
14+
var currentMonth = currentDate.getMonth() + 1; //Add 1 to month because 0 is January in JavaScript and 1 in Java
1415
var currentDay = currentDate.getDate();
1516
var currentHour = currentDate.getHours();
1617
var currentMinute = currentDate.getMinutes();
1718
var currentSecond = currentDate.getSeconds();
1819
var currentMillisecond = currentDate.getMilliseconds();
19-
year.value = currentYear;//set the input values to current local date and time
20+
year.value = currentYear; //set the input values to current local date and time
2021
month.value = currentMonth;
2122
day.value = currentDay;
2223
hour.value = currentHour;
@@ -26,6 +27,7 @@ function setCurrentDate() {
2627
microsecond.value = 0;
2728
nanosecond.value = 0;
2829
}
30+
2931
function setCurrentUtcDate() {
3032
var currentDate = new Date();
3133
var currentUtcYear = currentDate.getUTCFullYear();
@@ -35,7 +37,7 @@ function setCurrentUtcDate() {
3537
var currentUtcMinute = currentDate.getUTCMinutes();
3638
var currentUtcSecond = currentDate.getUTCSeconds();
3739
var currentUtcMillisecond = currentDate.getUTCMilliseconds();
38-
year.value = currentUtcYear;//set the input values to current UTC date and time
40+
year.value = currentUtcYear; //set the input values to current UTC date and time
3941
month.value = currentUtcMonth;
4042
day.value = currentUtcDay;
4143
hour.value = currentUtcHour;
@@ -45,6 +47,7 @@ function setCurrentUtcDate() {
4547
microsecond.value = 0;
4648
nanosecond.value = 0;
4749
}
50+
4851
function getDaysInMonth() {
4952
day.max = new Date(year.value, month.value, 0).getDate();
5053
if (day.value > day.max) {

0 commit comments

Comments
 (0)