Skip to content

Commit 7f62369

Browse files
committed
format sample code
1 parent 24a759b commit 7f62369

File tree

329 files changed

+5066
-5066
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

329 files changed

+5066
-5066
lines changed

app/src/main/assets/sample/CommonlyUsedJavaClasses/Calender/src/main/java/sample/AddDaysToCurrentDate.java

+36-36
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,42 @@
99

1010
public class AddDaysToCurrentDate {
1111

12-
public static void main(String[] args) {
13-
14-
//create Calendar instance
15-
Calendar now = Calendar.getInstance();
16-
17-
System.out.println(
18-
"Current date : "
19-
+ (now.get(Calendar.MONTH) + 1)
20-
+ "-"
21-
+ now.get(Calendar.DATE)
22-
+ "-"
23-
+ now.get(Calendar.YEAR));
24-
25-
//add days to current date using Calendar.add method
26-
now.add(Calendar.DATE, 1);
27-
28-
System.out.println(
29-
"date after one day : "
30-
+ (now.get(Calendar.MONTH) + 1)
31-
+ "-"
32-
+ now.get(Calendar.DATE)
33-
+ "-"
34-
+ now.get(Calendar.YEAR));
35-
36-
//substract days from current date using Calendar.add method
37-
now = Calendar.getInstance();
38-
now.add(Calendar.DATE, -10);
39-
40-
System.out.println(
41-
"date before 10 days : "
42-
+ (now.get(Calendar.MONTH) + 1)
43-
+ "-"
44-
+ now.get(Calendar.DATE)
45-
+ "-"
46-
+ now.get(Calendar.YEAR));
47-
}
12+
public static void main(String[] args) {
13+
14+
//create Calendar instance
15+
Calendar now = Calendar.getInstance();
16+
17+
System.out.println(
18+
"Current date : "
19+
+ (now.get(Calendar.MONTH) + 1)
20+
+ "-"
21+
+ now.get(Calendar.DATE)
22+
+ "-"
23+
+ now.get(Calendar.YEAR));
24+
25+
//add days to current date using Calendar.add method
26+
now.add(Calendar.DATE, 1);
27+
28+
System.out.println(
29+
"date after one day : "
30+
+ (now.get(Calendar.MONTH) + 1)
31+
+ "-"
32+
+ now.get(Calendar.DATE)
33+
+ "-"
34+
+ now.get(Calendar.YEAR));
35+
36+
//substract days from current date using Calendar.add method
37+
now = Calendar.getInstance();
38+
now.add(Calendar.DATE, -10);
39+
40+
System.out.println(
41+
"date before 10 days : "
42+
+ (now.get(Calendar.MONTH) + 1)
43+
+ "-"
44+
+ now.get(Calendar.DATE)
45+
+ "-"
46+
+ now.get(Calendar.YEAR));
47+
}
4848
}
4949

5050
/*

app/src/main/assets/sample/CommonlyUsedJavaClasses/Calender/src/main/java/sample/AddHoursToCurrentDate.java

+48-48
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,63 @@
99

1010
public class AddHoursToCurrentDate {
1111

12-
public static void main(String[] args) {
12+
public static void main(String[] args) {
1313

14-
//create Calendar instance
15-
Calendar now = Calendar.getInstance();
14+
//create Calendar instance
15+
Calendar now = Calendar.getInstance();
1616

17-
System.out.println(
18-
"Current Date : "
19-
+ (now.get(Calendar.MONTH) + 1)
20-
+ "-"
21-
+ now.get(Calendar.DATE)
22-
+ "-"
23-
+ now.get(Calendar.YEAR));
17+
System.out.println(
18+
"Current Date : "
19+
+ (now.get(Calendar.MONTH) + 1)
20+
+ "-"
21+
+ now.get(Calendar.DATE)
22+
+ "-"
23+
+ now.get(Calendar.YEAR));
2424

25-
System.out.println(
26-
"Current time : "
27-
+ now.get(Calendar.HOUR_OF_DAY)
28-
+ ":"
29-
+ now.get(Calendar.MINUTE)
30-
+ ":"
31-
+ now.get(Calendar.SECOND));
25+
System.out.println(
26+
"Current time : "
27+
+ now.get(Calendar.HOUR_OF_DAY)
28+
+ ":"
29+
+ now.get(Calendar.MINUTE)
30+
+ ":"
31+
+ now.get(Calendar.SECOND));
3232

33-
//add hours to current date using Calendar.add method
34-
now.add(Calendar.HOUR, 10);
33+
//add hours to current date using Calendar.add method
34+
now.add(Calendar.HOUR, 10);
3535

36-
System.out.println(
37-
"New time after adding 10 hours : "
38-
+ now.get(Calendar.HOUR_OF_DAY)
39-
+ ":"
40-
+ now.get(Calendar.MINUTE)
41-
+ ":"
42-
+ now.get(Calendar.SECOND));
36+
System.out.println(
37+
"New time after adding 10 hours : "
38+
+ now.get(Calendar.HOUR_OF_DAY)
39+
+ ":"
40+
+ now.get(Calendar.MINUTE)
41+
+ ":"
42+
+ now.get(Calendar.SECOND));
4343

44-
/*
45-
* Java Calendar class automatically adjust the date accordingly if adding
46-
* hours to the current time causes current date to be changed.
47-
*/
44+
/*
45+
* Java Calendar class automatically adjust the date accordingly if adding
46+
* hours to the current time causes current date to be changed.
47+
*/
4848

49-
System.out.println(
50-
"New date after adding 10 hours : "
51-
+ (now.get(Calendar.MONTH) + 1)
52-
+ "-"
53-
+ now.get(Calendar.DATE)
54-
+ "-"
55-
+ now.get(Calendar.YEAR));
49+
System.out.println(
50+
"New date after adding 10 hours : "
51+
+ (now.get(Calendar.MONTH) + 1)
52+
+ "-"
53+
+ now.get(Calendar.DATE)
54+
+ "-"
55+
+ now.get(Calendar.YEAR));
5656

57-
//substract hours from current date using Calendar.add method
58-
now = Calendar.getInstance();
59-
now.add(Calendar.HOUR, -3);
57+
//substract hours from current date using Calendar.add method
58+
now = Calendar.getInstance();
59+
now.add(Calendar.HOUR, -3);
6060

61-
System.out.println(
62-
"Time before 3 hours : "
63-
+ now.get(Calendar.HOUR_OF_DAY)
64-
+ ":"
65-
+ now.get(Calendar.MINUTE)
66-
+ ":"
67-
+ now.get(Calendar.SECOND));
68-
}
61+
System.out.println(
62+
"Time before 3 hours : "
63+
+ now.get(Calendar.HOUR_OF_DAY)
64+
+ ":"
65+
+ now.get(Calendar.MINUTE)
66+
+ ":"
67+
+ now.get(Calendar.SECOND));
68+
}
6969
}
7070

7171
/*

app/src/main/assets/sample/CommonlyUsedJavaClasses/Calender/src/main/java/sample/AddMinutesToCurrentDate.java

+35-35
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,47 @@
99

1010
public class AddMinutesToCurrentDate {
1111

12-
public static void main(String[] args) {
13-
14-
//create Calendar instance
15-
Calendar now = Calendar.getInstance();
16-
17-
System.out.println(
18-
"Current time : "
19-
+ now.get(Calendar.HOUR_OF_DAY)
20-
+ ":"
21-
+ now.get(Calendar.MINUTE)
22-
+ ":"
23-
+ now.get(Calendar.SECOND));
24-
25-
//add minutes to current date using Calendar.add method
26-
now.add(Calendar.MINUTE, 20);
27-
28-
System.out.println(
29-
"New time after adding 20 minutes : "
30-
+ now.get(Calendar.HOUR_OF_DAY)
31-
+ ":"
32-
+ now.get(Calendar.MINUTE)
33-
+ ":"
34-
+ now.get(Calendar.SECOND));
12+
public static void main(String[] args) {
13+
14+
//create Calendar instance
15+
Calendar now = Calendar.getInstance();
16+
17+
System.out.println(
18+
"Current time : "
19+
+ now.get(Calendar.HOUR_OF_DAY)
20+
+ ":"
21+
+ now.get(Calendar.MINUTE)
22+
+ ":"
23+
+ now.get(Calendar.SECOND));
24+
25+
//add minutes to current date using Calendar.add method
26+
now.add(Calendar.MINUTE, 20);
27+
28+
System.out.println(
29+
"New time after adding 20 minutes : "
30+
+ now.get(Calendar.HOUR_OF_DAY)
31+
+ ":"
32+
+ now.get(Calendar.MINUTE)
33+
+ ":"
34+
+ now.get(Calendar.SECOND));
3535

3636
/*
3737
* Java Calendar class automatically adjust the date or hour accordingly
3838
if adding minutes to the current time causes current hour or date to be changed.
3939
*/
4040

41-
//substract minutes from current date using Calendar.add method
42-
now = Calendar.getInstance();
43-
now.add(Calendar.MINUTE, -50);
44-
45-
System.out.println(
46-
"Time before 50 minutes : "
47-
+ now.get(Calendar.HOUR_OF_DAY)
48-
+ ":"
49-
+ now.get(Calendar.MINUTE)
50-
+ ":"
51-
+ now.get(Calendar.SECOND));
52-
}
41+
//substract minutes from current date using Calendar.add method
42+
now = Calendar.getInstance();
43+
now.add(Calendar.MINUTE, -50);
44+
45+
System.out.println(
46+
"Time before 50 minutes : "
47+
+ now.get(Calendar.HOUR_OF_DAY)
48+
+ ":"
49+
+ now.get(Calendar.MINUTE)
50+
+ ":"
51+
+ now.get(Calendar.SECOND));
52+
}
5353
}
5454

5555
/*

app/src/main/assets/sample/CommonlyUsedJavaClasses/Calender/src/main/java/sample/AddMonthsToCurrentDate.java

+36-36
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,42 @@
99

1010
public class AddMonthsToCurrentDate {
1111

12-
public static void main(String[] args) {
13-
14-
//create Calendar instance
15-
Calendar now = Calendar.getInstance();
16-
17-
System.out.println(
18-
"Current date : "
19-
+ (now.get(Calendar.MONTH) + 1)
20-
+ "-"
21-
+ now.get(Calendar.DATE)
22-
+ "-"
23-
+ now.get(Calendar.YEAR));
24-
25-
//add months to current date using Calendar.add method
26-
now.add(Calendar.MONTH, 10);
27-
28-
System.out.println(
29-
"date after 10 months : "
30-
+ (now.get(Calendar.MONTH) + 1)
31-
+ "-"
32-
+ now.get(Calendar.DATE)
33-
+ "-"
34-
+ now.get(Calendar.YEAR));
35-
36-
//substract months from current date using Calendar.add method
37-
now = Calendar.getInstance();
38-
now.add(Calendar.MONTH, -5);
39-
40-
System.out.println(
41-
"date before 5 months : "
42-
+ (now.get(Calendar.MONTH) + 1)
43-
+ "-"
44-
+ now.get(Calendar.DATE)
45-
+ "-"
46-
+ now.get(Calendar.YEAR));
47-
}
12+
public static void main(String[] args) {
13+
14+
//create Calendar instance
15+
Calendar now = Calendar.getInstance();
16+
17+
System.out.println(
18+
"Current date : "
19+
+ (now.get(Calendar.MONTH) + 1)
20+
+ "-"
21+
+ now.get(Calendar.DATE)
22+
+ "-"
23+
+ now.get(Calendar.YEAR));
24+
25+
//add months to current date using Calendar.add method
26+
now.add(Calendar.MONTH, 10);
27+
28+
System.out.println(
29+
"date after 10 months : "
30+
+ (now.get(Calendar.MONTH) + 1)
31+
+ "-"
32+
+ now.get(Calendar.DATE)
33+
+ "-"
34+
+ now.get(Calendar.YEAR));
35+
36+
//substract months from current date using Calendar.add method
37+
now = Calendar.getInstance();
38+
now.add(Calendar.MONTH, -5);
39+
40+
System.out.println(
41+
"date before 5 months : "
42+
+ (now.get(Calendar.MONTH) + 1)
43+
+ "-"
44+
+ now.get(Calendar.DATE)
45+
+ "-"
46+
+ now.get(Calendar.YEAR));
47+
}
4848
}
4949

5050
/*

0 commit comments

Comments
 (0)