How To Give-Up The Ghost Electrical Flow Date, Month, Twelvemonth In Addition To Twenty-Four Hours Of Calendar Week Inwards Coffee Program
Here is quick Java tip to larn electrical flow date, month, yr together with hateful solar daytime of calendar week from Java program. Java provides a rich Date together with Time API though having thread-safety issue only its rich inward business office together with if used locally tin move plough over you lot all the appointment together with fourth dimension information which you lot request for your corporation Java application. In final Java tutorial on Date together with Time API nosotros convey seen how to larn electrical flow appointment together with fourth dimension from unlike timezone using DateFormat together with SimpleDateFormat classes together with inward this post nosotros volition larn to a greater extent than or less to a greater extent than details similar electrical flow month, year, hateful solar daytime of calendar week etc yesteryear using java.util.Calendar class. Just continue inward hear that Calendar event should non locomote shared betwixt multiple threads. Calendar course of report inward Java provides unlike fields to larn unlike information e.g. Calendar.DATE gives you lot electrical flow appointment piece Calendar.MONTH gives you lot electrical flow calendar month based on what type of Calendar you lot are using, which depends upon locale.
Java programme to larn electrical flow month, year, appointment together with hateful solar daytime of calendar week
Here is consummate Java programme to larn diverse appointment together with fourth dimension related information using java.util.Calendar class. In this programme nosotros are retrieving electrical flow time, electrical flow day, electrical flow month, electrical flow year, electrical flow hateful solar daytime of calendar week together with electrical flow hateful solar daytime of calendar month to demonstrate rich functionality of java.util.Calendar class. Calendar tin move too locomote used to get electrical flow fourth dimension or appointment inward unlike timezone, which tin move locomote provided to Calendar course of report piece calling getInstance() method of java.util.Calendar.
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public class JavaCalendarExample {
public static void main(String args[]) {
//getting local time, date, hateful solar daytime of calendar week together with other details inward local timezone
Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
Date currentTime = localCalendar.getTime();
int currentDay = localCalendar.get(Calendar.DATE);
int currentMonth = localCalendar.get(Calendar.MONTH) + 1;
int currentYear = localCalendar.get(Calendar.YEAR);
int currentDayOfWeek = localCalendar.get(Calendar.DAY_OF_WEEK);
int currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
int CurrentDayOfYear = localCalendar.get(Calendar.DAY_OF_YEAR);
System.out.println("Current Date together with fourth dimension details inward local timezone");
System.out.println("Current Date: " + currentTime);
System.out.println("Current Day: " + currentDay);
System.out.println("Current Month: " + currentMonth);
System.out.println("Current Year: " + currentYear);
System.out.println("Current Day of Week: " + currentDayOfWeek);
System.out.println("Current Day of Month: " + currentDayOfMonth);
System.out.println("Current Day of Year: " + CurrentDayOfYear);
//getting time, date, hateful solar daytime of calendar week together with other details inward GMT timezone
Calendar gmtCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
//rest of materials are same
}
}
Output:
Current Date: Monday January 16 05:25:34 VET 2012
Current Day: 16
Current Month: 1
Current Year: 2012
Current Day of Week: 2
Current Day of Month: 16
Current Day of Year: 16
import java.util.Date;
import java.util.TimeZone;
public class JavaCalendarExample {
public static void main(String args[]) {
//getting local time, date, hateful solar daytime of calendar week together with other details inward local timezone
Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
Date currentTime = localCalendar.getTime();
int currentDay = localCalendar.get(Calendar.DATE);
int currentMonth = localCalendar.get(Calendar.MONTH) + 1;
int currentYear = localCalendar.get(Calendar.YEAR);
int currentDayOfWeek = localCalendar.get(Calendar.DAY_OF_WEEK);
int currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
int CurrentDayOfYear = localCalendar.get(Calendar.DAY_OF_YEAR);
System.out.println("Current Date together with fourth dimension details inward local timezone");
System.out.println("Current Date: " + currentTime);
System.out.println("Current Day: " + currentDay);
System.out.println("Current Month: " + currentMonth);
System.out.println("Current Year: " + currentYear);
System.out.println("Current Day of Week: " + currentDayOfWeek);
System.out.println("Current Day of Month: " + currentDayOfMonth);
System.out.println("Current Day of Year: " + CurrentDayOfYear);
//getting time, date, hateful solar daytime of calendar week together with other details inward GMT timezone
Calendar gmtCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
//rest of materials are same
}
}
Output:
Current Date: Monday January 16 05:25:34 VET 2012
Current Day: 16
Current Month: 1
Current Year: 2012
Current Day of Week: 2
Current Day of Month: 16
Current Day of Year: 16
That’s all on how to larn electrical flow day,current calendar month together with yr , electrical flow hateful solar daytime of moth together with hateful solar daytime of calendar week inward Java . As I said Date together with Time API inward Java is really rich only has to a greater extent than or less serious upshot similar SimpleDateFormat is non thread-safe only hoping to larn these upshot resolved before long when Java 8 is coming amongst novel Date together with Time API. There is all the same an alternative amongst JODA Date together with Time API only that is ever minute choice to me because of additional dependency on project.
Further Learning
Complete Java Masterclass
How to format Date inward dd-mm-yy format inward Java
Belum ada Komentar untuk "How To Give-Up The Ghost Electrical Flow Date, Month, Twelvemonth In Addition To Twenty-Four Hours Of Calendar Week Inwards Coffee Program"
Posting Komentar