How To Become Electrical Flow Date, Month, Twelvemonth As Well As Twenty-Four Hours Of Calendar Week Inwards Coffee Program

Advertisement

Masukkan script iklan 970x90px

How To Become Electrical Flow Date, Month, Twelvemonth As Well As Twenty-Four Hours Of Calendar Week Inwards Coffee Program

Sabtu, 16 Mei 2020

Here is quick Java tip to larn electrical flow date, month, yr in addition to solar daytime of calendar week from Java program. Java provides a rich Date in addition to Time API though having thread-safety issue simply its rich inward component division in addition to if used locally tin hand y'all all the appointment in addition to fourth dimension information which y'all take away for your company Java application. In terminal Java tutorial on Date in addition to Time API nosotros bring 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 around to a greater extent than details similar electrical flow month, year, solar daytime of calendar week etc yesteryear using java.util.Calendar class.  Just boot the bucket on inward take away heed that Calendar event should non live on shared betwixt multiple threads. Calendar aeroplane inward Java provides dissimilar fields to larn dissimilar information e.g. Calendar.DATE gives y'all electrical flow appointment piece Calendar.MONTH gives y'all electrical flow calendar month based on what type of Calendar y'all are using, which depends upon locale.


Java computer program to larn electrical flow month, year, appointment in addition to solar daytime of calendar week

Here is quick Java tip to larn electrical flow appointment How to larn electrical flow date, month, yr in addition to solar daytime of calendar week inward Java programHere is consummate Java computer program to larn diverse appointment in addition to fourth dimension related information using java.util.Calendar class. In this computer program nosotros are retrieving electrical flow time, electrical flow day, electrical flow month, electrical flow year, electrical flow solar daytime of calendar week in addition to electrical flow solar daytime of calendar month to demonstrate rich functionality of java.util.Calendar class. Calendar tin too live on used to get electrical flow fourth dimension or appointment inward dissimilar timezone, which tin live on provided to Calendar aeroplane 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 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, solar daytime 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 yr , electrical flow solar daytime of moth in addition to solar daytime of calendar week inward Java . As I said Date in addition to Time API inward Java is real rich simply has around serious termination similar SimpleDateFormat is non thread-safe simply hoping to larn these termination resolved presently when Java 8 is coming alongside novel Date in addition to Time API. There is all the same an option alongside JODA Date in addition to Time API simply that is ever minute selection to me because of additional dependency on project.

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