Skip to content

Commit 134652c

Browse files
authored
I stood on sand of the sea, & saw a beast rise up
And I stood upon the sand of the sea, and saw a beast rise up out of the sea, having seven heads and ten horns, and upon his horns ten crowns, and upon his heads the name of blasphemy (Revelation 13:1)
1 parent ab9947a commit 134652c

File tree

1 file changed

+165
-0
lines changed

1 file changed

+165
-0
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
2+
//And I stood upon the sand of the sea, and saw a beast rise up out of the sea, having seven heads and ten horns, and upon his horns ten crowns, and upon his heads the name of blasphemy (Revelation 13:1)
3+
4+
package com.javarush.task.task40.task4007;
5+
6+
import java.text.ParseException;
7+
import java.text.SimpleDateFormat;
8+
import java.util.Calendar;
9+
10+
/*
11+
Работа с датами
12+
*/
13+
14+
public class Solution {
15+
public static void main(String[] args) {
16+
printDate("21.4.2014 15:56:45");
17+
System.out.println();
18+
printDate("21.4.2014");
19+
System.out.println();
20+
printDate("17:33:40");
21+
}
22+
23+
public static void printDate(String date) {
24+
boolean containsDate = false; //напишите тут ваш код
25+
boolean containsTime = false;
26+
27+
Calendar calendar = Calendar.getInstance();
28+
SimpleDateFormat simpleDateFormat = null;
29+
30+
if (date.contains(":")) {
31+
simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
32+
containsTime = true;
33+
}
34+
35+
if (date.contains(".")) {
36+
simpleDateFormat = new SimpleDateFormat("dd.MM.yy");
37+
containsDate = true;
38+
}
39+
40+
41+
if (date.contains(" ")) {
42+
simpleDateFormat = new SimpleDateFormat("dd.MM.yy HH:mm:ss");
43+
containsDate = true;
44+
containsTime = true;
45+
}
46+
47+
if (simpleDateFormat == null)
48+
return;
49+
50+
try {
51+
calendar.setTime(simpleDateFormat.parse(date));
52+
} catch (ParseException e) {
53+
return;
54+
}
55+
56+
if (containsDate) {
57+
System.out.println("День: " + calendar.get(Calendar.DATE));
58+
System.out.println("День недели: " + ((calendar.get(Calendar.DAY_OF_WEEK) - 1) == 0 ? 7 : calendar.get(Calendar.DAY_OF_WEEK) - 1));
59+
System.out.println("День месяца: " + calendar.get(Calendar.DAY_OF_MONTH));
60+
System.out.println("День года: " + calendar.get(Calendar.DAY_OF_YEAR));
61+
System.out.println("Неделя месяца: " + calendar.get(Calendar.WEEK_OF_MONTH));
62+
System.out.println("Неделя года: " + calendar.get(Calendar.WEEK_OF_YEAR));
63+
System.out.println("Месяц: " + (calendar.get(Calendar.MONTH) + 1));
64+
System.out.println("Год: " + calendar.get(Calendar.YEAR));
65+
}
66+
67+
if (containsTime) {
68+
System.out.println("AM или PM: " + (calendar.get(Calendar.AM_PM) == 0 ? "AM" : "PM"));
69+
System.out.println("Часы: " + calendar.get(Calendar.HOUR));
70+
System.out.println("Часы дня: " + calendar.get(Calendar.HOUR_OF_DAY));
71+
System.out.println("Минуты: " + calendar.get(Calendar.MINUTE));
72+
System.out.println("Секунды: " + calendar.get(Calendar.SECOND));
73+
}
74+
}
75+
}
76+
77+
/*
78+
Работа с датами
79+
80+
Реализуй метод printDate(String date).
81+
82+
Он должен в качестве параметра принимать дату (в одном из 3х форматов) и выводить ее в консоль в соответствии с примером:
83+
84+
85+
86+
1) Для "21.4.2014 15:56:45" вывод должен быть:
87+
88+
День: 21
89+
90+
День недели: 1
91+
92+
День месяца: 21
93+
94+
День года: 111
95+
96+
Неделя месяца: 4
97+
98+
Неделя года: 17
99+
100+
Месяц: 4
101+
102+
Год: 2014
103+
104+
AM или PM: PM
105+
106+
Часы: 3
107+
108+
Часы дня: 15
109+
110+
Минуты: 56
111+
112+
Секунды: 45
113+
114+
115+
116+
2) Для "21.4.2014":
117+
118+
День: 21
119+
120+
День недели: 1
121+
122+
День месяца: 21
123+
124+
День года: 111
125+
126+
Неделя месяца: 4
127+
128+
Неделя года: 17
129+
130+
Месяц: 4
131+
132+
Год: 2014
133+
134+
135+
136+
3) Для "17:33:40":
137+
138+
AM или PM: PM
139+
140+
Часы: 5
141+
142+
Часы дня: 17
143+
144+
Минуты: 33
145+
146+
Секунды: 40
147+
148+
149+
150+
Используй класс Calendar.
151+
152+
153+
154+
155+
156+
Требования:
157+
158+
1. Если в метод printDate передана дата в формате "дата время", он должен вывести: День, День недели, День месяца, День года, Неделя месяца, Неделя года, Месяц, Год, AM или PM, Часы, Часы дня, Минуты, Секунды.
159+
160+
2. Если в метод printDate передана дата в формате "дата", он должен вывести: День, День недели, День месяца, День года, Неделя месяца, Неделя года, Месяц, Год.
161+
162+
3. Если в метод printDate передана дата в формате "время", он должен вывести: AM или PM, Часы, Часы дня, Минуты, Секунды.
163+
164+
4. Используй статический метод getInstance класса Calendar для получения календаря.
165+
*/

0 commit comments

Comments
 (0)