How To Boot The Bucket Electrical Flow Date, Month, Yr As Well As Twenty-Four Hours Of Calendar Week Inwards Coffee Program

Here is quick Java tip to larn electrical flow date, month, yr too solar daytime of calendar week from Java program. Java provides a rich Date too Time API though having thread-safety issue exactly its rich inwards role too if used locally tin hand you lot all the appointment too fourth dimension information which you lot involve for your company Java application. In concluding Java tutorial on Date too Time API nosotros bring seen how to larn electrical flow appointment too fourth dimension from unlike timezone using DateFormat too SimpleDateFormat classes too inwards this ship service nosotros volition larn roughly to a greater extent than details similar electrical flow month, year, solar daytime of calendar week etc past times using java.util.Calendar class.  Just continue inwards heed that Calendar event should non live on shared betwixt multiple threads. Calendar cast inwards 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 too solar daytime of calendar week

Here is quick Java tip to larn electrical flow appointment How to larn electrical flow date, month, yr too solar daytime of calendar week inwards Java programHere is consummate Java programme to larn diverse appointment too 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 solar daytime of calendar week too electrical flow solar daytime of calendar month to demonstrate rich functionality of java.util.Calendar class. Calendar tin likewise live on used to get electrical flow fourth dimension or appointment inwards unlike timezone, which tin live on provided to Calendar cast 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, solar daytime of calendar week too 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 too 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, solar daytime of calendar week too 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 larn electrical flow day,current calendar month too yr , electrical flow solar daytime of moth too solar daytime of calendar week inwards Java . As I said Date too Time API inwards Java is rattling rich exactly has roughly serious effect similar SimpleDateFormat is non thread-safe exactly hoping to larn these effect resolved presently when Java 8 is coming amongst novel Date too Time API. There is nonetheless an alternative amongst JODA Date too Time API exactly that is ever minute alternative to me because of additional dependency on project.

Further Learning
Complete Java Masterclass
How to format Date inwards dd-mm-yy format inwards Java

Komentar