JapaneseDate atTime() method in Java with Example
Last Updated :
27 Mar, 2020
The atTime() method of java.time.chrono.JapaneseDate class is used to add up this JapaneseDate time with a local time for producing an equivalent date and time .
Syntax:
public final ChronoLocalDateTime
atTime(LocalTime localTime)
Parameter: This method takes the object of type LocalTime as a parameter.
Return Value: This method returns the Chrono local date time by adding up this japanese date with the passed local time.
Below are the examples to illustrate the atTime() method:
Example 1:
Java
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] argv)
{
try {
JapaneseDate hidate
= JapaneseDate.now();
LocalTime localtime
= LocalTime.now();
ChronoLocalDateTime<JapaneseDate> date
= hidate.atTime(localtime);
System.out.println(
"Chrono LocalDateTime is: "
+ date);
}
catch (DateTimeException e) {
System.out.println(
"passed parameter can"
+ " not form a date" );
System.out.println(
"Exception thrown: " + e);
}
}
}
|
Output
Chrono LocalDateTime is: Japanese Heisei 32-03-18T17:18:51.528
Example 2:
Java
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
public class GFG {
public static void main(String[] argv)
{
try {
JapaneseDate hidate
= JapaneseDate.now();
LocalTime localtime
= LocalTime.of( 8 , 20 );
ChronoLocalDateTime<JapaneseDate> date
= hidate.atTime(localtime);
System.out.println(
"Chrono LocalDateTime is: "
+ date);
}
catch (DateTimeException e) {
System.out.println(
"passed parameter can"
+ " not form a date" );
System.out.println(
"Exception thrown: " + e);
}
}
}
|
Output
Chrono LocalDateTime is: Japanese Heisei 32-03-18T08:20
Reference:https://docs.oracle.com/javase/9/docs/api/java/time/chrono/JapaneseDate.html#atTime-java.time.LocalTime-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...