Skip to content

Commit 1e7fff7

Browse files
committed
added 3 examples for time conversion
1 parent 9adaf8d commit 1e7fff7

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,66 @@ try {
431431
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
432432
}
433433
```
434+
### Time Conversion API
435+
```java
436+
// Convert time using timezone ID with the provided time
437+
TimezoneConvertParams timezoneConvertParams =
438+
TimezoneConvertParams.builder()
439+
.withTimeZone("America/New_York", "Asia/Karachi")
440+
.withDateTime("2024-02-29 16:40")
441+
.build();
442+
443+
try {
444+
TimezoneConvert tzConverted = ipGeolocationAPI.convertTimeZone(timezoneConvertParams);
445+
446+
System.out.println("Original time: " + tzConverted.getOriginalTime());
447+
System.out.println("Converted time: " + tzConverted.getConvertedTime());
448+
System.out.println("Difference in hours: " + tzConverted.getDiffHour());
449+
}catch (IPGeolocationError e) {
450+
// on unsuccessful lookup or invalid input IPGeolocationError is thrown
451+
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
452+
}
453+
```
454+
```java
455+
// Convert time using locations with current time
456+
TimezoneConvertParams timezoneConvertParams =
457+
TimezoneConvertParams.builder()
458+
.withLocation("Lahore, Pakistan", "London, United Kingdom")
459+
.build();
460+
461+
try {
462+
TimezoneConvert tzConverted = ipGeolocationAPI.convertTimeZone(timezoneConvertParams);
463+
464+
System.out.println("Original time: " + tzConverted.getOriginalTime());
465+
System.out.println("Converted time: " + tzConverted.getConvertedTime());
466+
System.out.println("Difference in minutes: " + tzConverted.getDiffMin());
467+
}catch (IPGeolocationError e) {
468+
// on unsuccessful lookup or invalid input IPGeolocationError is thrown
469+
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
470+
}
471+
```
472+
```java
473+
// Convert time using Geo Coordinates of locations with the provided time
474+
TimezoneConvertParams timezoneConvertParams =
475+
TimezoneConvertParams.builder()
476+
.withCoordinates(
477+
BigDecimal.valueOf(31.522165), BigDecimal.valueOf(74.358422),
478+
BigDecimal.valueOf(38.907084), BigDecimal.valueOf(-77.03449))
479+
.withDateTime("2024-02-29 16:40:40")
480+
.build();
481+
482+
try {
483+
TimezoneConvert tzConverted = ipGeolocationAPI.convertTimeZone(timezoneConvertParams);
484+
485+
System.out.println("Original time: " + tzConverted.getOriginalTime());
486+
System.out.println("Converted time: " + tzConverted.getConvertedTime());
487+
System.out.println("Difference in hours: " + tzConverted.getDiffHour());
488+
}catch (IPGeolocationError e) {
489+
// on unsuccessful lookup or invalid input IPGeolocationError is thrown
490+
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
491+
}
492+
```
493+
434494

435495
** IPGeolocation provides geolocation information in the following languages:
436496

0 commit comments

Comments
 (0)