How To Snuff It Electrical Flow Date, Month, Twelvemonth As Well As Twenty-Four Hr Flow Of Calendar Week Inwards Coffee Program
Here is quick Java tip to larn electrical flow date, month, twelvemonth in addition to twenty-four threescore minutes catamenia of calendar week from Java program. Java provides a rich Date in addition to Time API though having thread-safety issue but its rich inward component division in addition to if used locally tin hand you lot all the appointment in addition to fourth dimension information which you lot involve for your corporation Java application. In concluding Java tutorial on Date in addition to Time API nosotros convey seen how to larn electrical flow appointment in addition to fourth dimension from dissimilar timezone using DateFormat in addition to SimpleDateFormat classes in addition to inward this post service nosotros volition larn simply about to a greater extent than details similar electrical flow month, year, twenty-four threescore minutes catamenia of calendar week etc past times using java.util.Calendar class. Just overstep away on inward hear that Calendar event should non live on shared betwixt multiple threads. Calendar bird inward Java provides dissimilar fields to larn dissimilar information e.g. Calendar.DATE gives you lot electrical flow appointment spell Calendar.MONTH gives you lot electrical flow calendar month based on what type of Calendar you lot are using, which depends upon locale.
Java computer programme to larn electrical flow month, year, appointment in addition to twenty-four threescore minutes catamenia of calendar week
Here is consummate Java computer programme to larn diverse appointment in addition to fourth dimension related information using java.util.Calendar class. In this computer programme nosotros are retrieving electrical flow time, electrical flow day, electrical flow month, electrical flow year, electrical flow twenty-four threescore minutes catamenia of calendar week in addition to electrical flow twenty-four threescore minutes catamenia of calendar month to demonstrate rich functionality of java.util.Calendar class. Calendar tin every bit good live on used to get electrical flow fourth dimension or appointment inward dissimilar timezone, which tin live on provided to Calendar bird 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, twenty-four threescore minutes catamenia of calendar week in addition to 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 in addition to 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, twenty-four threescore minutes catamenia of calendar week in addition to 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, twenty-four threescore minutes catamenia of calendar week in addition to 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 in addition to 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, twenty-four threescore minutes catamenia of calendar week in addition to 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 in addition to twelvemonth , electrical flow twenty-four threescore minutes catamenia of moth in addition to twenty-four threescore minutes catamenia of calendar week inward Java . As I said Date in addition to Time API inward Java is real rich but has simply about serious final result similar SimpleDateFormat is non thread-safe but hoping to larn these final result resolved shortly when Java 8 is coming amongst novel Date in addition to Time API. There is nevertheless an alternative amongst JODA Date in addition to Time API but that is ever 2nd alternative to me because of additional dependency on project.
Further Learning
Complete Java Masterclass
How to format Date inward dd-mm-yy format inward Java
0 Response to "How To Snuff It Electrical Flow Date, Month, Twelvemonth As Well As Twenty-Four Hr Flow Of Calendar Week Inwards Coffee Program"
Post a Comment