Java Date Format Check checkTime(int id)

Here you can find the source of checkTime(int id)

Description

Check time.

License

Apache License

Parameter

Parameter Description
id the id

Return

the string

Declaration

public static String checkTime(int id) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DateFormat;

import java.util.Calendar;

import java.util.GregorianCalendar;
import java.util.Locale;

public class Main {
    /**//from   ww w.j  a  v  a2 s.  co m
     * Check time.
     *
     * @param id the id
     * @return the string
     */
    public static String checkTime(int id) {
        String bol = "";
        Calendar tt = Calendar.getInstance();
        String currDate = getNowDate();
        System.out.println("currDate=" + currDate);
        int result = tt.get(Calendar.DAY_OF_WEEK);

        int shour = tt.get(Calendar.HOUR_OF_DAY);

        if (id == 3) {
            switch (result) {
            case 1:
                break;
            case 7:
                if ((shour >= 8) && (shour < 12)) {
                    bol = "disabled";
                    break;
                }
            default:
                if ((shour >= 8) && (shour < 12)) {
                    bol = "disabled";
                    break;
                } else if ((shour >= 14) && (shour < 17)) {
                    bol = "disabled";
                    break;
                }
            }
        }
        return bol;
    }

    /**
     * Gets the now date.
     *
     * @return the now date
     */
    public static String getNowDate() {
        GregorianCalendar gcNow = new GregorianCalendar();
        java.util.Date dNow = gcNow.getTime();
        DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.SIMPLIFIED_CHINESE);
        return df.format(dNow);
    }
}

Related

  1. checkDateFormat(String strTime, String pattern)
  2. checkDateFormatAndValite(String strDateTime, String format)
  3. checkDateInToday(Date date)
  4. checkDateRange(String fromDate, String endDate)
  5. checkDateValidity(String str, String formatString)
  6. checkTimestamp(String timestamp)