Skip to content

Commit 7140dc7

Browse files
committed
Merge pull request '对时区中的文章 Java 中的 ZoneOffset 进行更新' (#36) from lic into main
Reviewed-on: https://src.isharkfly.com/iSharkFly-Docs/java-tutorials/pulls/36
2 parents 51c2547 + 350cb41 commit 7140dc7

17 files changed

Lines changed: 230 additions & 6 deletions

.idea/compiler.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core-java-modules/core-java-8-datetime/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
## Java 8+ Date and Time API
1+
## Java 8+ Date Time API
22

3-
This module contains articles about the Date and Time API introduced with Java 8.
3+
本模块中包含的内容有关 Java 8 中使用日期和时间的 API
44

5-
### Relevant Articles:
5+
### 相关文章:
66
- [Introduction to the Java 8 Date/Time API](http://www.baeldung.com/java-8-date-time-intro)
77
- [Migrating to the New Java 8 Date Time API](http://www.baeldung.com/migrating-to-java-8-date-time-api)
88
- [Get the Current Date and Time in Java](https://www.baeldung.com/current-date-time-and-timestamp-in-java-8)
99
- [TemporalAdjuster in Java](http://www.baeldung.com/java-temporal-adjuster)
10-
- [ZoneOffset in Java](https://www.baeldung.com/java-zone-offset)
10+
- [Java 中的 ZoneOffset](https://www.isharkfly.com/t/java-zoneoffset/16803)
1111
- [Differences Between ZonedDateTime and OffsetDateTime](https://www.baeldung.com/java-zoneddatetime-offsetdatetime)
1212
- [Period and Duration in Java](http://www.baeldung.com/java-period-duration)
1313
- [How to Get the Start and the End of a Day using Java](http://www.baeldung.com/java-day-start-end)

core-java-modules/core-java-8-datetime/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<name>core-java-8-datetime</name>
99

1010
<parent>
11-
<groupId>com.baeldung.core-java-modules</groupId>
11+
<groupId>com.ossez.core-java-modules</groupId>
1212
<artifactId>core-java-modules</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
13+
<version>0.0.2-SNAPSHOT</version>
1414
</parent>
1515

1616
<dependencies>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.datetime;
2+
3+
import java.text.ParseException;
4+
import java.util.Calendar;
5+
import java.util.Date;
6+
7+
public class CalendarUtils {
8+
public static Calendar getPlusDays(Date date, int amount) throws ParseException {
9+
Calendar calendar = Calendar.getInstance();
10+
calendar.setTime(date);
11+
calendar.add(Calendar.DAY_OF_YEAR, amount);
12+
return calendar;
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.baeldung.datetime;
2+
3+
import java.text.SimpleDateFormat;
4+
import java.text.ParseException;
5+
import java.util.Date;
6+
public class DateUtils {
7+
8+
public static Date getNow() {
9+
return new Date();
10+
}
11+
12+
public static Date getDate(long millis) {
13+
return new Date(millis);
14+
}
15+
16+
public static Date getDate(String dateAsString, String pattern) throws ParseException {
17+
return new SimpleDateFormat(pattern).parse(dateAsString);
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.baeldung.datetime;
2+
3+
import java.text.SimpleDateFormat;
4+
import java.util.Date;
5+
import java.util.TimeZone;
6+
7+
public class UseSimpleDateFormat {
8+
9+
public String useFormat() {
10+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
11+
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata"));
12+
Date date = new Date(1725437542000L);
13+
return sdf.format(date);
14+
}
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.datetime.sql;
2+
3+
import java.sql.Date;
4+
import java.text.ParseException;
5+
import java.text.SimpleDateFormat;
6+
7+
public class DateUtils {
8+
9+
public static Date getNow() {
10+
return new Date(System.currentTimeMillis());
11+
}
12+
13+
public static Date getDate(String dateAsString) {
14+
return Date.valueOf(dateAsString);
15+
}
16+
17+
public static Date getDate(String dateAsString, String pattern) throws ParseException {
18+
java.util.Date customUtilDate = new SimpleDateFormat(pattern).parse(dateAsString);
19+
return new Date(customUtilDate.getTime());
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.datetime.sql;
2+
3+
import java.sql.Time;
4+
import java.text.ParseException;
5+
import java.text.SimpleDateFormat;
6+
7+
public class TimeUtils {
8+
9+
public static Time getNow() {
10+
return new Time(System.currentTimeMillis());
11+
}
12+
13+
public static Time getTime(String timeAsString) {
14+
return Time.valueOf(timeAsString);
15+
}
16+
17+
public static Time getTime(String dateAsString, String pattern) throws ParseException {
18+
java.util.Date customUtilDate = new SimpleDateFormat(pattern).parse(dateAsString);
19+
return new Time(customUtilDate.getTime());
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.baeldung.datetime.sql;
2+
3+
import java.sql.Timestamp;
4+
import java.text.ParseException;
5+
import java.text.SimpleDateFormat;
6+
7+
public class TimestampUtils {
8+
9+
public static Timestamp getNow() {
10+
return new Timestamp(System.currentTimeMillis());
11+
}
12+
13+
public static Timestamp getTimestamp(String timestampAsString) {
14+
return Timestamp.valueOf(timestampAsString);
15+
}
16+
17+
public static Timestamp getTimestamp(String dateAsString, String pattern) throws ParseException {
18+
java.util.Date customUtilDate = new SimpleDateFormat(pattern).parse(dateAsString);
19+
return new Timestamp(customUtilDate.getTime());
20+
}
21+
}

0 commit comments

Comments
 (0)