Example usage for java.util Calendar HOUR_OF_DAY

List of usage examples for java.util Calendar HOUR_OF_DAY

Introduction

In this page you can find the example usage for java.util Calendar HOUR_OF_DAY.

Prototype

int HOUR_OF_DAY

To view the source code for java.util Calendar HOUR_OF_DAY.

Click Source Link

Document

Field number for get and set indicating the hour of the day.

Usage

From source file:MainClass.java

public static void main(String[] args) {

    // get a calendar using the default time zone and locale.
    Calendar calendar = Calendar.getInstance();

    // set Date portion to January 1, 1970
    calendar.set(Calendar.YEAR, 1970);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DATE, 1);

    // normalize the object
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime());
}

From source file:Main.java

public static void main(String[] args) {

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:00Z");
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, 2015);
    cal.set(Calendar.MONTH, Calendar.SEPTEMBER);
    cal.set(Calendar.DATE, 1);/*from w w  w. j av a  2  s.  co m*/
    cal.set(Calendar.HOUR_OF_DAY, 12);
    cal.set(Calendar.MINUTE, 15);
    Date date = cal.getTime();
    System.out.println(date);
    TimeZone tz = TimeZone.getTimeZone("IST");
    dateFormat.setTimeZone(tz);
    String actual = dateFormat.format(date);

    System.out.println(actual);
}

From source file:Main.java

public static void main(String[] args) {
    Calendar someTime = Calendar.getInstance();
    someTime.set(Calendar.HOUR_OF_DAY, 17);
    someTime.set(Calendar.MINUTE, 0);
    someTime.set(Calendar.SECOND, 0);

    // convert it to java epoch date
    Date someDate = toEpochDate(someTime);

    // create a date object from java.sql.Time
    Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime());

    // now do the comparison
    System.out.println("Some Date: " + someDate.toString());
    System.out.println("Sql Time: " + fromSqlTime.toString());
    System.out.println("Are they equal? " + someDate.equals(fromSqlTime));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
    Date workDate = simpleDateFormat1.parse("2011-11-27");

    Calendar workCalendar = Calendar.getInstance();
    workCalendar.setTime(workDate);/*from ww w . jav a 2  s .c  o m*/
    SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("HH:mm:ss");
    Calendar time = Calendar.getInstance();
    time.setTime(simpleDateFormat2.parse("06:00:00"));
    workCalendar.set(Calendar.HOUR_OF_DAY, time.get(Calendar.HOUR_OF_DAY));
    workCalendar.set(Calendar.MINUTE, time.get(Calendar.MINUTE));
    workCalendar.set(Calendar.SECOND, time.get(Calendar.SECOND));

    Date newWorkDate = workCalendar.getTime();

    SimpleDateFormat simpleDateFormat3 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    System.out.println(simpleDateFormat3.format(newWorkDate));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    // Get the current time in Hong Kong
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("Hongkong"));

    int hour12 = cal.get(Calendar.HOUR); // 0..11
    int minutes = cal.get(Calendar.MINUTE); // 0..59
    int seconds = cal.get(Calendar.SECOND); // 0..59
    boolean am = cal.get(Calendar.AM_PM) == Calendar.AM;

    // Get the current hour-of-day at GMT
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    int hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23

    // Get the current local hour-of-day
    cal.setTimeZone(TimeZone.getDefault());
    hour24 = cal.get(Calendar.HOUR_OF_DAY); // 0..23
}

From source file:camera.Camera.java

/**
 * @param args the command line arguments
 *//*w ww . j a v a2 s  . co m*/
public static void main(String[] args) throws Exception {
    System.out.println("start compass.");
    //   Compass c = new Compass();
    //   c.start();
    System.out.println("start camera.");
    Camera cam = new Camera();
    cam.snapshot();
    // regelmssig zu festen Sekunden Foto schiessen. Thread.
    int phase;
    int lastPhase = -1;
    while (true) {
        Calendar cal = new GregorianCalendar();
        int stunde = cal.get(Calendar.HOUR_OF_DAY);
        int STUNDE_VON = 7;
        int STUNDE_BIS = 23;
        if ((stunde < STUNDE_VON) || (stunde > STUNDE_BIS)) {
            Thread.sleep(1000);
            continue;
        }
        // regelmssig Fotos
        int sekunde = cal.get(Calendar.SECOND);
        phase = sekunde / 10; // alle 10 sekunden wechsel  jede volle zehner wechselt
        //phase = phase % 4; // 4 phasen wenn ma unterteilen wollte

        if (phase == lastPhase) {
            //    Thread.sleep(300);
            //      continue;
        }
        lastPhase = phase;
        // zeit fr ein Foto.
        cam.snapshot();

    }
}

From source file:DayWeek.java

public static void main(String[] av) {
    //+/*  w w  w .  j  a  va2s .  c  om*/
    Calendar c = Calendar.getInstance(); // today

    System.out.println("Year: " + c.get(Calendar.YEAR));
    System.out.println("Month: " + c.get(Calendar.MONTH));
    System.out.println("Day: " + c.get(Calendar.DAY_OF_MONTH));
    System.out.println("Day of week = " + c.get(Calendar.DAY_OF_WEEK));
    System.out.println("Day of year = " + c.get(Calendar.DAY_OF_YEAR));
    System.out.println("Week in Year: " + c.get(Calendar.WEEK_OF_YEAR));
    System.out.println("Week in Month: " + c.get(Calendar.WEEK_OF_MONTH));
    System.out.println("Day of Week in Month: " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("Hour: " + c.get(Calendar.HOUR));
    System.out.println("AM or PM: " + c.get(Calendar.AM_PM));
    System.out.println("Hour (24-hour clock): " + c.get(Calendar.HOUR_OF_DAY));
    System.out.println("Minute: " + c.get(Calendar.MINUTE));
    System.out.println("Second: " + c.get(Calendar.SECOND));
    //-
}

From source file:info.usbo.skypetwitter.Run.java

public static void main(String[] args) {
    System.out.println("Working Directory = " + System.getProperty("user.dir"));
    Properties props;//from ww w.j  ava2  s .  c  o  m
    props = (Properties) System.getProperties().clone();
    //loadProperties(props, "D:\\Data\\Java\\classpath\\twitter.props");
    work_dir = System.getProperty("user.dir");
    loadProperties(props, work_dir + "\\twitter.props");
    twitter_user_id = props.getProperty("twitter.user");
    twitter_timeout = Integer.parseInt(props.getProperty("twitter.timeout"));
    System.out.println("Twitter user: " + twitter_user_id);
    System.out.println("Twitter timeout: " + twitter_timeout);
    if ("".equals(twitter_user_id)) {
        return;
    }
    if (load_file() == 0) {
        System.out.println("File not found");
        return;
    }
    while (true) {
        bChanged = 0;
        /*
        create_id();
        Chat ch = Chat.getInstance(chat_group_id);
        ch.send("!");
        */
        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm");
        System.out.println("Looking at " + sdf.format(Calendar.getInstance().getTime()));
        Chat ch = Chat.getInstance(chat_group_id);
        Twitter twitter = new TwitterFactory().getInstance();
        try {
            List<Status> statuses;
            statuses = twitter.getUserTimeline(twitter_user_id);
            //System.out.println("Showing @" + twitter_user_id + "'s user timeline.");
            String sText;
            for (Status status : statuses) {
                //System.out.println(status.getId());
                Date d = status.getCreatedAt();
                //   ?
                Calendar cal = Calendar.getInstance();
                cal.setTime(d);
                cal.add(Calendar.HOUR_OF_DAY, 7);
                d = cal.getTime();
                sText = "@" + status.getUser().getScreenName() + "  " + sdf.format(d)
                        + " ( https://twitter.com/" + twitter_user_id + "/status/" + status.getId() + " ): \r\n"
                        + status.getText() + "\r\n***";
                for (URLEntity e : status.getURLEntities()) {
                    sText = sText.replaceAll(e.getURL(), e.getExpandedURL());
                }
                for (MediaEntity e : status.getMediaEntities()) {
                    sText = sText.replaceAll(e.getURL(), e.getMediaURL());
                }
                if (twitter_ids.indexOf(status.getId()) == -1) {
                    System.out.println(sText);
                    ch.send(sText);
                    twitter_ids.add(status.getId());
                    bChanged = 1;
                }
            }
        } catch (TwitterException te) {
            te.printStackTrace();
            System.out.println("Failed to get timeline: " + te.getMessage());
            //System.exit(-1);
        } catch (SkypeException ex) {
            ex.printStackTrace();
            System.out.println("Failed to send message: " + ex.getMessage());
        }

        // VK
        try {
            vk();
            for (VK v : vk) {
                if (vk_ids.indexOf(v.getId()) == -1) {
                    Date d = v.getDate();
                    //   ?
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(d);
                    cal.add(Calendar.HOUR_OF_DAY, 7);
                    d = cal.getTime();
                    String sText = "@Depersonilized (VK)  " + sdf.format(d)
                            + " ( http://vk.com/Depersonilized?w=wall-0_" + v.getId() + " ): \r\n"
                            + v.getText();
                    if (!"".equals(v.getAttachment())) {
                        sText += "\r\n" + v.getAttachment();
                    }
                    sText += "\r\n***";
                    System.out.println(sText);
                    ch.send(sText);
                    vk_ids.add(v.getId());
                    bChanged = 1;
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
            System.out.println("Failed to get vk: " + e.getMessage());
            //System.exit(-1);
        } catch (SkypeException ex) {
            ex.printStackTrace();
            System.out.println("Failed to send message: " + ex.getMessage());
        }
        if (bChanged == 1) {
            save_file();
        }
        try {
            Thread.sleep(1000 * 60 * twitter_timeout);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
            System.out.println("Failed to sleep: " + ex.getMessage());
        }
    }
}

From source file:Main.java

public static void toBeginOfDay(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
    cal.clear(Calendar.MINUTE);/*from www  . j  a v a  2s  . c o  m*/
    cal.clear(Calendar.SECOND);
    cal.clear(Calendar.MILLISECOND);
}

From source file:Main.java

public static int getHour() {
    return Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
}