Example usage for java.util Date getDay

List of usage examples for java.util Date getDay

Introduction

In this page you can find the example usage for java.util Date getDay.

Prototype

@Deprecated
public int getDay() 

Source Link

Document

Returns the day of the week represented by this date.

Usage

From source file:de.forsthaus.webui.calendar.model.CalendarDateFormatter.java

/**
 * This is for showing the Daynames in the month view, means mold="month" .<br>
 * EN: on top of every column the 2 digits day name is shown.<br>
 * DE: oberhalb jeder Spalte wird der Tagesnamen (2-stellig) angezeigt.<br>
 *///w  w w.j a va 2s .  com
@Override
public String getCaptionByDayOfWeek(Date date, Locale locale, TimeZone timezone) {

    String day = null;

    if (date.getDay() == 0) {
        day = Labels.getLabel("common.dayname.sunday.3");
    } else if (date.getDay() == 1) {
        day = Labels.getLabel("common.dayname.monday.3");
    } else if (date.getDay() == 2) {
        day = Labels.getLabel("common.dayname.tuesday.3");
    } else if (date.getDay() == 3) {
        day = Labels.getLabel("common.dayname.wednesday.3");
    } else if (date.getDay() == 4) {
        day = Labels.getLabel("common.dayname.thursday.3");
    } else if (date.getDay() == 5) {
        day = Labels.getLabel("common.dayname.friday.3");
    } else if (date.getDay() == 6) {
        day = Labels.getLabel("common.dayname.saturday.3");
    }

    day = StringUtils.capitalize(day.toLowerCase());

    return day;
}

From source file:nz.co.fortytwo.signalk.util.Util.java

/**
 * Attempt to set the system time using the GPS time
 * //from  www .ja v a  2s.com
 * @param sen
 */
@SuppressWarnings("deprecation")
public static void checkTime(RMCSentence sen) {
    if (timeSet)
        return;
    try {
        net.sf.marineapi.nmea.util.Date dayNow = sen.getDate();
        // if we need to set the time, we will be WAAYYY out
        // we only try once, so we dont get lots of native processes
        // spawning if we fail
        timeSet = true;
        Date date = new Date();
        if ((date.getYear() + 1900) == dayNow.getYear()) {
            if (logger.isDebugEnabled())
                logger.debug("Current date is " + date);
            return;
        }
        // so we need to set the date and time
        net.sf.marineapi.nmea.util.Time timeNow = sen.getTime();
        String yy = String.valueOf(dayNow.getYear());
        String MM = pad(2, String.valueOf(dayNow.getMonth()));
        String dd = pad(2, String.valueOf(dayNow.getDay()));
        String hh = pad(2, String.valueOf(timeNow.getHour()));
        String mm = pad(2, String.valueOf(timeNow.getMinutes()));
        String ss = pad(2, String.valueOf(timeNow.getSeconds()));
        if (logger.isDebugEnabled())
            logger.debug("Setting current date to " + dayNow + " " + timeNow);
        String cmd = "sudo date --utc " + MM + dd + hh + mm + yy + "." + ss;
        Runtime.getRuntime().exec(cmd.split(" "));// MMddhhmm[[yy]yy]
        if (logger.isDebugEnabled())
            logger.debug("Executed date setting command:" + cmd);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

}

From source file:com.dare2date.externeservice.lastfm.LastfmAPI.java

/**
 * Adds date data to an event.// w w  w.j a  va 2 s .c  o m
 * @param eventdata
 * @param event
 */
private void addDateToEventFromJSONData(JSONObject eventdata, LastfmEvent event) {
    try {
        Calendar date = Calendar.getInstance();
        Date _date = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.ENGLISH)
                .parse(eventdata.get("startDate").toString());
        date.set(_date.getYear(), _date.getMonth(), _date.getDay(), _date.getHours(), _date.getMinutes(),
                _date.getSeconds());
        event.setStartDate(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:de.forsthaus.webui.calendar.model.CalendarDateFormatter.java

/**
 * This is for the day/week view, means mold="default" .<br>
 * EN: Mo 09/12 | Dayshort month/day<br>
 * DE: Mo 12.09 | Tageskuerzel Tag.Monat<br>
 *//*w ww  . j  ava 2s  .  c  om*/
@Override
public String getCaptionByDate(Date date, Locale locale, TimeZone timezone) {

    String sDate = ZksampleDateFormat.getDayMonthFormater().format(date);
    String day = null;

    if (date.getDay() == 0) {
        day = Labels.getLabel("common.dayname.sunday.2");
    } else if (date.getDay() == 1) {
        day = Labels.getLabel("common.dayname.monday.2");
    } else if (date.getDay() == 2) {
        day = Labels.getLabel("common.dayname.tuesday.2");
    } else if (date.getDay() == 3) {
        day = Labels.getLabel("common.dayname.wednesday.2");
    } else if (date.getDay() == 4) {
        day = Labels.getLabel("common.dayname.thursday.2");
    } else if (date.getDay() == 5) {
        day = Labels.getLabel("common.dayname.friday.2");
    } else if (date.getDay() == 6) {
        day = Labels.getLabel("common.dayname.saturday.2");
    }

    day = StringUtils.capitalize(day.toLowerCase());
    String result = day + " " + sDate;

    return result;
}

From source file:Logic.mongoC.java

public void masInter(String usuario) {
    HashMap<String, String> conteo = new HashMap();
    Document soloN = this.coll.find(eq("ScreenName", usuario)).first();
    usuario regreso = this.gson.fromJson(soloN.getString("todo"), usuario.class);
    for (twitt t : regreso.getTimeline()) {
        Date d = t.getFecha();
        System.out.println(d.getDay());
        for (String men : t.getPersonas()) {
            if (conteo.containsKey(men)) {
                int cl = Integer.valueOf(conteo.get(men));
                cl++;/*from   www.ja va 2  s  .  c  o m*/
                conteo.put(men, String.valueOf(cl));

            } else {
                conteo.put(men, "1");
            }
        }
    }
    JFreeChart Grafica;
    DefaultCategoryDataset Datos = new DefaultCategoryDataset();

    for (Map.Entry<String, String> entry : conteo.entrySet()) {
        String key = entry.getKey().toString();
        Integer value = Integer.valueOf(entry.getValue());
        Datos.addValue(value, usuario, key);
        System.out.println("KEY " + key + " vaue " + value);
    }

    Grafica = ChartFactory.createBarChart("Interacciones con usuarios", "Usuarios", "Numero de interacciones",
            Datos, PlotOrientation.VERTICAL, true, true, false);

    ChartPanel Panel = new ChartPanel(Grafica);
    JFrame Ventana = new JFrame("JFreeChart");
    Ventana.getContentPane().add(Panel);
    Ventana.pack();
    Ventana.setVisible(true);
    Ventana.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

From source file:com.javielinux.utils.Utils.java

public static String timeFromTweet(Context cnt, Date timeTweet) {

    if (Integer.parseInt(Utils.getPreference(cnt).getString("prf_date_format", "1")) == 1) {
        return diffDate(new Date(), timeTweet);
    } else {// ww w.ja v a  2s.  c om
        Date now = new Date();
        if (now.getDay() == timeTweet.getDay() && now.getMonth() == timeTweet.getMonth()
                && now.getYear() == timeTweet.getYear()) {
            return DateFormat.getTimeInstance().format(timeTweet);
        } else {
            return DateFormat.getDateInstance().format(timeTweet);
        }
    }

}

From source file:Logic.mongoC.java

public void diasTweet(String usuario) {
    HashMap<String, String> conteo = new HashMap();
    conteo.put("Lunes", "0");
    conteo.put("Martes", "0");
    conteo.put("Miercoles", "0");
    conteo.put("Jueves", "0");
    conteo.put("Viernes", "0");
    conteo.put("Sabado", "0");
    conteo.put("Domingo", "0");
    Document soloN = this.coll.find(eq("ScreenName", usuario)).first();
    usuario regreso = this.gson.fromJson(soloN.getString("todo"), usuario.class);
    for (twitt t : regreso.getTimeline()) {
        Date d = t.getFecha();
        int dia = d.getDay();
        if (dia == 1) {
            int cl = Integer.valueOf(conteo.get("Lunes"));
            cl++;/*from  ww  w.  jav  a  2 s.c  om*/
            conteo.put("Lunes", String.valueOf(cl));
        }
        if (dia == 2) {
            int cl = Integer.valueOf(conteo.get("Martes"));
            cl++;
            conteo.put("Martes", String.valueOf(cl));
        }
        if (dia == 3) {
            int cl = Integer.valueOf(conteo.get("Miercoles"));
            cl++;
            conteo.put("Miercoles", String.valueOf(cl));
        }
        if (dia == 4) {
            int cl = Integer.valueOf(conteo.get("Jueves"));
            cl++;
            conteo.put("Jueves", String.valueOf(cl));
        }
        if (dia == 5) {
            int cl = Integer.valueOf(conteo.get("Viernes"));
            cl++;
            conteo.put("Viernes", String.valueOf(cl));
        }
        if (dia == 6) {
            int cl = Integer.valueOf(conteo.get("Sabado"));
            cl++;
            conteo.put("Sabado", String.valueOf(cl));
        }
        if (dia == 7) {
            int cl = Integer.valueOf(conteo.get("Domingo"));
            cl++;
            conteo.put("Domingo", String.valueOf(cl));
        }

    }
    JFreeChart Grafica;
    DefaultCategoryDataset Datos = new DefaultCategoryDataset();

    for (Map.Entry<String, String> entry : conteo.entrySet()) {
        String key = entry.getKey().toString();
        Integer value = Integer.valueOf(entry.getValue());
        Datos.addValue(value, usuario, key);
        System.out.println("KEY " + key + " vaue " + value);
    }

    Grafica = ChartFactory.createBarChart("Tweets por dia", "Dias", "Numero de Tweets", Datos,
            PlotOrientation.VERTICAL, true, true, false);

    ChartPanel Panel = new ChartPanel(Grafica);
    JFrame Ventana = new JFrame("JFreeChart");
    Ventana.getContentPane().add(Panel);
    Ventana.pack();
    Ventana.setVisible(true);
    Ventana.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}

From source file:webservice.ImportantPlacesWorker.java

public List<double[]> getImportantPlaces() {
    Iterator it = locationsMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry) it.next();
        Map data = (Map) locationsMap.get(pair.getKey());
        String timestamp = (String) data.get("timestamp");
        Date currentDate = new Date(timestamp);
        int hours = currentDate.getHours();
        timestamp = getTimeZone(hours);/*from   w  w w.ja va 2s  .c o  m*/
        String activity = "undefined";
        String place = "undefined";
        String day_of_the_week = daysOfTheWeek[currentDate.getDay()];
        if (data.get("status") != null) {
            activity = (String) data.get("status");
        }
        if (data.get("place") != null) {
            place = (String) data.get("place");
        }
        // Get recorded latitude and longitude
        Map mCoordinate = (HashMap) data.get("location");
        currentLatitude = (double) (mCoordinate.get("latitude"));
        currentLongitude = (double) (mCoordinate.get("longitude"));
        String speed = "0-5";
        if (previousLatitude != 0 && previousLongitude != 0 && previousDate != null) {
            speed = calculateSpeed(previousDate.getTime() / 1000, previousLatitude, previousLongitude,
                    currentDate.getTime() / 1000, currentLatitude, currentLongitude);
        }
        previousDate = currentDate;
        previousLatitude = currentLatitude;
        previousLongitude = currentLongitude;
        // writeToFile(writerPoints, currentLatitude +"," + currentLongitude+"\n");
        //System.out.println(ctivity);
        if (activity.equals("Still") || activity.equals("Sleeping")) {
            points.add(new DoublePoint(createPoint(currentLatitude, currentLongitude)));
        }

    }
    clusterPoints();
    return centerPoints;
}

From source file:com.krawler.esp.servlets.importProjectPlanCSV.java

public static String getActualDuration_importCSV(Date stdate, Date enddate, int[] NonWorkDays,
        String[] holidays, String duration) {
    Double noofdays = 0.0;/* w ww  .jav a  2  s.c  o  m*/
    java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd");
    try {
        Calendar c1 = Calendar.getInstance();
        while (stdate.compareTo(enddate) < 0) {
            if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0
                    && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) {
                noofdays++;
            }
            c1.setTime(stdate);
            c1.add(Calendar.DATE, 1);
            stdate = sdf1.parse(sdf1.format(c1.getTime()));
        }
        if (stdate.compareTo(enddate) == 0) {
            if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0
                    && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) {
                if (duration.equals("")) {
                    noofdays++;
                } else {
                    int dur1 = Integer.parseInt(duration.substring(0, 1));
                    if (dur1 == 0) {
                        noofdays = 0.0;
                    } else {
                        noofdays++;
                    }
                }
            }
        }
    } catch (ParseException ex) {
        Logger.getLogger(importProjectPlanCSV.class.getName()).log(Level.SEVERE, null, ex);
    }
    return String.valueOf(noofdays);
}

From source file:pa_SymposiumPlanner.RuleML2010RRChair.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {//from  w  w w . j  a  v a 2  s .  com
        address = PAConfiguration.getAddress();
        port = PAConfiguration.getPort(instantiation);
        poslAddress = PAConfiguration.getPOSL(instantiation, topic);
        rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation);
        messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic);
    } catch (BadConfigurationException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
        System.exit(0);
    }
    try {
        System.out.println("RR Chair Servlet");
        System.out.println(response.toString());

        BufferedReader brd = request.getReader();

        String input = "";
        String message = "";

        while (!input.equals("</RuleML>")) {

            input = brd.readLine();

            message = message + input;
        }
        String[] varOrder = getVariableOrder(message);
        System.out.println("Received Message: " + message);

        //   BackwardReasoner br = new BackwardReasoner();
        //   Iterator solit =null;
        //   DefiniteClause dc = null;
        //   SymbolTable.reset();

        POSLParser pp = new POSLParser();
        // String contents = "c(a).\nc(b).\nc(c).";

        Date t1 = new GregorianCalendar().getTime();
        System.out.println(t1.getHours() + ":" + t1.getMinutes());
        //append time to contents

        System.out.println("day: " + t1.getDay());
        System.out.println("day: " + t1.getYear());
        System.out.println("day: " + t1.getMonth());

        //time
        String time = "time(" + t1.getHours() + ":integer).";
        System.out.println(time);

        String url = poslAddress;

        //String url = "http://www.jdrew.org/oojdrew/test.posl";
        String contents = "";

        //day of the week
        int day = t1.getDay();
        boolean weekday = true;

        if (day == 0 || day == 6) {
            weekday = false;
        }

        String dayOfWeek;

        if (weekday) {
            dayOfWeek = "day(weekday).";
        } else {
            dayOfWeek = "day(weekend).";
        }
        //full date
        Calendar cal = new GregorianCalendar();

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        int day2 = cal.get(Calendar.DAY_OF_MONTH);

        String date;

        String day3 = "" + day2;

        if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8
                || day2 == 9) {

            day3 = "0" + day2;
        }

        if (month == 10 || month == 11 || month == 12) {
            date = "" + year + month + day3;
        } else {
            date = "" + year + "0" + month + day3;
        }

        date = "date(" + date + ":integer).";

        System.out.println(date);

        String url2 = rdfAddress;
        HttpClient client2 = new HttpClient();
        GetMethod method2 = new GetMethod(url2);
        method2.setFollowRedirects(true);
        String typestr = "";
        // Execute the GET method
        int statusCode2 = client2.executeMethod(method2);
        if (statusCode2 != -1) {
            typestr = method2.getResponseBodyAsString();
        }
        try {
            Types.reset();

            RDFSParser.parseRDFSString(typestr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            HttpClient client = new HttpClient();
            GetMethod method = new GetMethod(url);
            method.setFollowRedirects(true);

            // Execute the GET method
            int statusCode = client.executeMethod(method);
            if (statusCode != -1) {
                contents = method.getResponseBodyAsString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        contents = contents + "\n" + time;
        contents = contents + "\n" + dayOfWeek;
        contents = contents + "\n" + date;

        BackwardReasoner br = new BackwardReasoner();
        Iterator solit = null;
        DefiniteClause dc = null;
        SymbolTable.reset();
        pp.parseDefiniteClauses(contents);

        br.loadClauses(pp.iterator());

        Iterator it = pp.iterator();
        while (it.hasNext()) {
            DefiniteClause d = (DefiniteClause) it.next();
            System.out.println("Loaded clause: " + d.toPOSLString());
        }

        br = new BackwardReasoner(br.clauses, br.oids);

        MessageParser m = new MessageParser(message);
        Element atom = null;

        try {
            atom = m.parseForContent();
        } catch (Exception e) {
            System.out.println("Invalid Message");
            //out.flush();
        }
        QueryBuilder q = new QueryBuilder(atom);
        String query = q.generateDoc();
        System.out.println("ABOUT TO INPUT THIS QUERY:" + query);
        RuleMLParser qp = new RuleMLParser();

        try {
            dc = qp.parseRuleMLQuery(query);
        } catch (Exception e) {
            System.out.println("Invalid Query");
            //out.flush();
        }

        //solit = br.iterativeDepthFirstSolutionIterator(dc);

        solit = br.iterativeDepthFirstSolutionIterator(dc);
        int varSize = 0;
        while (solit.hasNext()) {
            Vector data = new Vector();
            BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next();

            Hashtable varbind = gl.varBindings;
            javax.swing.tree.DefaultMutableTreeNode root = br.toTree();
            root.setAllowsChildren(true);

            javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root);

            int i = 0;
            Object[][] rowdata = new Object[varbind.size()][2];
            varSize = varbind.size();

            Enumeration e = varbind.keys();
            while (e.hasMoreElements()) {
                Object k = e.nextElement();
                Object val = varbind.get(k);
                String ks = (String) k;
                rowdata[i][0] = ks;
                rowdata[i][1] = val;

                i++;
            }
            data.addElement(rowdata);
            String[] messages = new String[data.size()];
            MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(),
                    m.getProtocol(), m.getRel(), varOrder);
            messages = g.Messages2();

            String appender = "";

            URL sender = new URL(address + ":" + port);
            HttpMessage msg = new HttpMessage(sender);
            Properties props = new Properties();

            for (int i1 = 0; i1 < data.size(); i1++) {
                System.out.println(i1 + ")" + messages[i1].toString());
                props.put("text", messages[i1].toString());
                InputStream in = msg.sendGetMessage(props);
            }
            System.out.println("NEXT MESSAGE");
        }

        MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(),
                m.getRel());

        URL sender = new URL(address + ":" + port);
        HttpMessage msg = new HttpMessage(sender);
        Properties props = new Properties();

        String finalMessage = g.finalMessage(query);
        System.out.println("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn");
        System.out.println(finalMessage);

        props.put("text", finalMessage);
        InputStream in = msg.sendGetMessage(props);

        System.out.println("Stop_Communication");

    } catch (Exception e) {
        System.out.println("ERROR has occured : " + e.toString());
    }
    out.close();
}