How To Top Away Electrical Current Date, Month, Yr Too Hateful Solar Daytime Of Calendar Week Inward Coffee Program
Wednesday, June 13, 2018
Add Comment
Here is quick Java tip to teach electrical flow date, month, yr together with 24-hour interval of calendar week from Java program. Java provides a rich Date together with Time API though having thread-safety issue only its rich inwards business office together with if used locally tin laissez passer yous all the engagement together with fourth dimension information which yous require for your company Java application. In concluding Java tutorial on Date together with Time API nosotros accept seen how to teach electrical flow engagement together with fourth dimension from unlike timezone using DateFormat together with SimpleDateFormat classes together with inwards this post nosotros volition teach around to a greater extent than details similar electrical flow month, year, 24-hour interval of calendar week etc past times using java.util.Calendar class. Just continue inwards heed that Calendar illustration should non endure shared betwixt multiple threads. Calendar degree inwards Java provides unlike fields to teach unlike information e.g. Calendar.DATE gives yous electrical flow engagement spell Calendar.MONTH gives yous electrical flow calendar month based on what type of Calendar yous are using, which depends upon locale.
Java programme to teach electrical flow month, year, engagement together with 24-hour interval of calendar week
Here is consummate Java programme to teach diverse engagement 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 24-hour interval of calendar week together with electrical flow 24-hour interval of calendar month to demonstrate rich functionality of java.util.Calendar class. Calendar tin equally good endure used to get electrical flow fourth dimension or engagement inwards unlike timezone, which tin endure provided to Calendar degree spell 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, 24-hour interval of calendar week together with other details inwards 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 inwards 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, 24-hour interval of calendar week together with other details inwards 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, 24-hour interval of calendar week together with other details inwards 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 inwards 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, 24-hour interval of calendar week together with other details inwards 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 teach electrical flow day,current calendar month together with yr , electrical flow 24-hour interval of moth together with 24-hour interval of calendar week inwards Java . As I said Date together with Time API inwards Java is really rich only has around serious effect similar SimpleDateFormat is non thread-safe only hoping to teach these effect resolved before long when Java 8 is coming amongst novel Date together with Time API. There is nevertheless an choice amongst JODA Date together with Time API only that is ever mo selection to me because of additional dependency on project.
Further Learning
Complete Java Masterclass
How to format Date inwards dd-mm-yy format inwards Java
0 Response to "How To Top Away Electrical Current Date, Month, Yr Too Hateful Solar Daytime Of Calendar Week Inward Coffee Program"
Post a Comment