Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Calendar;

public class Main {
    public static String getDateString() {
        String stringDate = "";
        Calendar calendar = Calendar.getInstance();
        int day = calendar.get(Calendar.DAY_OF_WEEK);
        int month = calendar.get(Calendar.MONTH);
        int dayInt = calendar.get(Calendar.DAY_OF_MONTH);
        switch (day) {
        case Calendar.SUNDAY:
            stringDate += "Sunday";
            break;

        case Calendar.MONDAY:
            stringDate += "Monday";
            break;

        case Calendar.TUESDAY:
            stringDate += "Tuesday";
            break;

        case Calendar.WEDNESDAY:
            stringDate += "Wednesday";
            break;

        case Calendar.THURSDAY:
            stringDate += "Thursday";
            break;

        case Calendar.FRIDAY:
            stringDate += "Friday";
            break;

        case Calendar.SATURDAY:
            stringDate += "Saturday";
            break;

        }
        switch (month) {
        case Calendar.JANUARY:
            stringDate += ", January";
            break;

        case Calendar.FEBRUARY:
            stringDate += ", February";
            break;

        case Calendar.MARCH:
            stringDate += ", March";
            break;

        case Calendar.APRIL:
            stringDate += ", April";
            break;

        case Calendar.MAY:
            stringDate += ", May";
            break;

        case Calendar.JUNE:
            stringDate += ", June";
            break;

        case Calendar.JULY:
            stringDate += ", July";
            break;

        case Calendar.AUGUST:
            stringDate += ", August";
            break;

        case Calendar.SEPTEMBER:
            stringDate += ", September";
            break;

        case Calendar.OCTOBER:
            stringDate += ", October";
            break;

        case Calendar.NOVEMBER:
            stringDate += ", November";
            break;

        case Calendar.DECEMBER:
            stringDate += ", December";
            break;

        }

        stringDate += (" " + dayInt);

        return stringDate;
    }
}