+ 1
This code is not giving me the expected result please help me resolve it.
package Calendar; import java.text.SimpleDateFormat; import java.util.Calendar; public class date { public static void main(String[] args) { Calendar time = Calendar.getInstance(); SimpleDateFormat tTime = new SimpleDateFormat("hh:mm:ss"); tTime.format(time.getTime()); SimpleDateFormat tDate = new SimpleDateFormat("dd:mm:yy"); tTime.format(time.getTime()); System.out.print("The time is " + tTime +"\t"); System.out.print("Today's date is " + tDate); } }
3 Antworten
+ 1
Anyway, both Calendar and Date classes are outdated. I suggest you to read about and use LocalDate, LocalTime and LocalDateTime.
+ 1
Aleksandrs Kalinins write to me through inbox.
0
SimpleDateFormat works with Date class. Try this:
public class Example {
public static void main(String[] args) {
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
String strDate= formatter.format(date);
System.out.println(strDate);
}
}