Java Timestamp dayNumber(Timestamp stamp)

Here you can find the source of dayNumber(Timestamp stamp)

Description

returns a day number in a week for a Timestamp input

License

Apache License

Parameter

Parameter Description
stamp Timestamp date

Return

A int containing the day number (sunday = 1, saturday = 7)

Declaration

public static int dayNumber(Timestamp stamp) 

Method Source Code


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

import java.sql.Timestamp;

import java.util.Calendar;
import java.util.Date;

import java.util.Locale;
import java.util.TimeZone;

public class Main {
    /**//w  ww . j a va 2 s . c  om
     * returns a day number in a week for a Timestamp input
     *
     * @param stamp
     *            Timestamp date
     * @return A int containing the day number (sunday = 1, saturday = 7)
     */
    public static int dayNumber(Timestamp stamp) {
        Calendar tempCal = toCalendar(stamp, TimeZone.getDefault(), Locale.getDefault());
        return tempCal.get(Calendar.DAY_OF_WEEK);
    }

    public static java.util.Calendar toCalendar(java.sql.Timestamp stamp) {
        Calendar cal = Calendar.getInstance();
        if (stamp != null) {
            cal.setTimeInMillis(stamp.getTime());
        }
        return cal;
    }

    /**
     * Returns a Calendar object initialized to the specified date/time, time
     * zone, and locale.
     *
     * @param date
     *            date/time to use
     * @param timeZone
     * @param locale
     * @return Calendar object
     * @see java.util.Calendar
     */
    public static Calendar toCalendar(Date date, TimeZone timeZone, Locale locale) {
        Calendar cal = Calendar.getInstance(timeZone, locale);
        if (date != null) {
            cal.setTime(date);
        }
        return cal;
    }
}

Related

  1. datesDiffer(Timestamp a, Timestamp b)
  2. dateStringToTimestamp(String dateStr)
  3. datetime2ToTimestamp(long value, int fraction, int width)
  4. dateTimeToString(Timestamp dt, String df)
  5. dateToOracleStr(java.sql.Timestamp ts)
  6. daysBetween(Timestamp t1, Timestamp t2)
  7. delta_hours(Timestamp startdate, Timestamp enddate)
  8. differDayByNow(Timestamp timestamp)
  9. doubleToTimestamp(double f)