Example usage for java.util Date getYear

List of usage examples for java.util Date getYear

Introduction

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

Prototype

@Deprecated
public int getYear() 

Source Link

Document

Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

Usage

From source file:irille.pub.svr.DateUtils.java

public static Date getMonthBefore(Date date) {
    return new Date(date.getYear(), date.getMonth() - 1, date.getDate());
}

From source file:irille.pub.svr.DateUtils.java

public static Date getDateSub(Date date, int sub) {
    return new Date(date.getYear(), date.getMonth(), date.getDate() - sub);
}

From source file:Main.java

public static String getXMLDateString() {
    Date date = new Date();
    // YYYY-MM-DDThh:mm:ss

    // Must be a simpler way to do this....
    String xmlDateFormat = "" + (date.getYear() + 1900);
    int month = (date.getMonth() + 1);
    String monthStr = fillZero(month);
    String dateStr = fillZero(date.getDate());
    xmlDateFormat = xmlDateFormat + "-" + monthStr;
    xmlDateFormat = xmlDateFormat + "-" + dateStr;
    xmlDateFormat = xmlDateFormat + "T" + fillZero(date.getHours());
    xmlDateFormat = xmlDateFormat + ":" + fillZero(date.getMinutes());
    xmlDateFormat = xmlDateFormat + ":" + fillZero(date.getSeconds());

    return (xmlDateFormat);
}

From source file:Main.java

public static int compareDates(java.util.Date startDate, java.util.Date endDate) {
    int interval = 0;

    calendarStartDate = Calendar.getInstance();
    calendarStartDate.set(Calendar.YEAR, startDate.getYear());
    calendarStartDate.set(Calendar.MONTH, startDate.getMonth());
    calendarStartDate.set(Calendar.DAY_OF_MONTH, startDate.getDate());

    calendarEndDate.set(Calendar.YEAR, endDate.getYear());
    calendarEndDate.set(Calendar.MONTH, endDate.getMonth());
    calendarEndDate.set(Calendar.DAY_OF_MONTH, endDate.getDate());

    long diff = calendarEndDate.getTimeInMillis() - calendarStartDate.getTimeInMillis();
    interval = (int) (diff / (24 * 60 * 60 * 1000) + 1); // plus one day

    return interval;
}

From source file:ch.ethz.inf.vs.android.g54.a4.util.SnapshotCache.java

private static String constructFileName(String name) {
    Date d = new Date();
    return String.format("%d-%d-%d_%d-%d-%d_%s.%s", d.getYear() + 1900, d.getMonth(), d.getDay(), d.getHours(),
            d.getMinutes(), d.getSeconds(), name, FILE_EXTENSION);
}

From source file:Main.java

public static int getYear(String sDate) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date d = null;
    try {/*from  ww w .  j  a  va2 s .  c  om*/
        d = df.parse(sDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    if (d == null) {
        return 1971;
    }
    return d.getYear() + 1900;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static String dateFormat(long stamp) {
    Date date = new Date(stamp * 1000);
    Date today = new Date();

    SimpleDateFormat format;/*from   www.j  ava  2 s  .c o  m*/
    if (date.getDate() == today.getDate()) {
        format = new SimpleDateFormat("HH:mm");
    } else if (date.getYear() == today.getYear()) {
        format = new SimpleDateFormat("MM-dd HH:mm");
    } else {
        format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    }

    return format.format(date);
}

From source file:commonUtils.FunctionUtils.java

public static String DateToDirView() {
    Date inDate = DateTimeUtils.getNow();
    String sYear = ConvertUtils.toString(inDate.getYear() + 1900);
    int iNumber = inDate.getMonth() + 1;
    String sMonth = iNumber >= 10 ? ConvertUtils.toString(iNumber) : "0" + ConvertUtils.toString(iNumber);
    iNumber = inDate.getDate();/*from w w w. ja  v a2 s.c  om*/
    String sDay = iNumber >= 10 ? ConvertUtils.toString(iNumber) : "0" + ConvertUtils.toString(iNumber);

    return ConvertUtils.toString(sYear + sMonth + sDay);
}

From source file:Main.java

public static boolean IsDiferentDate(Date date1, Date date2) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date1);/*w w w  .java  2  s .  c  om*/
    int daysInYear1 = calendar.get(Calendar.DAY_OF_YEAR);

    calendar = Calendar.getInstance();
    calendar.setTime(date2);
    int daysInYear2 = calendar.get(Calendar.DAY_OF_YEAR);

    if (daysInYear1 != daysInYear2 || date1.getYear() != date2.getYear()) {
        return true;
    }

    return false;
}

From source file:org.agmip.ui.utils.WeatherFileSystem.java

public static void WriteToFile() {

    // prepare the file name from the organization name and the site index number and then write to that file
    String orgName = DssatUtil.getInfo(AppKeys.FARM);
    String siteIndex = DssatUtil.getInfo("SiteIndex");
    File file = new File(PathGenerator.getWeatherFilePath());

    String writeBuffer = null;/*from   w  w  w. j  a va 2  s. c  o  m*/

    PrintWriter pr = null;
    try {
        pr = new PrintWriter(file);
        writeBuffer = new String("*WEATHER : \n");
        pr.println(writeBuffer);
        writeBuffer = new String("@ INSI      LAT     LONG  ELEV   TAV   AMP REFHT WNDHT");
        pr.println(writeBuffer);

        double latitude = -34.23;
        double longitude = -34.23;
        double elevation = -99;
        double tavg = -99;
        double tamp = -99;
        double tmht = -99;
        double wmht = -99;

        writeBuffer = new String();
        //Empty 2 Char, Org 2 Char, Site 2Char, Space 1 Char, latitude 8Chars with 3 dec
        writeBuffer = String.format(
                "%.2s%.2s%.2s%.1s%8.3f%.1s%8.3f%.1s%5.0f%.1s%5.1f%.1s%5.1f%.1s%5.1f%.1s%5.1f", "  ", orgName,
                siteIndex, " ", latitude, " ", longitude, " ", elevation, " ", tavg, " ", tamp, " ", tmht, " ",
                wmht);
        pr.println(writeBuffer);

        int julianday = 56001;
        double solarrad = -99;
        double tmax = -99;
        double tmin = -99;
        double rain = -99;
        double dewp = -99;
        double wind = -99;
        double par = -99;

        writeBuffer = new String("@DATE  SRAD  TMAX  TMIN  RAIN  RHUM  WIND  TDEW  PAR");
        pr.println(writeBuffer);
        writeBuffer = new String();

        URL url = null;
        InputStream is = null;
        Integer plantingyear;
        if (DssatUtil.getInfo("PlantingYear") != null) {
            plantingyear = Integer.parseInt(DssatUtil.getInfo("PlantingYear"));
        } else {
            Date d = new Date();
            plantingyear = d.getYear() + 1900;
        }
        /*Bring the Weather details for last 10 Years and write the details to the WTH File. */
        try {

            String query = new String("SELECT%20*%20FROM%20FAWN_historic_daily_20140212%20"
                    + "WHERE%20(%20yyyy%20BETWEEN%20" + (plantingyear - 10) + "%20AND%20"
                    + plantingyear.toString() + ")" + "%20AND%20(%20LocId%20=%20"
                    + DssatUtil.getInfo(AppKeys.STATION_LOCATION_ID) + ")" + "%20ORDER%20BY%20yyyy%20DESC%20");

            String urlStr = "http://abe.ufl.edu/bmpmodel/xmlread/rohit.php?sql=" + query;

            System.out.println("********************************");
            System.out.println(urlStr);

            //System.out.println(urlStr);
            URL uflconnection = new URL(urlStr);
            HttpURLConnection huc = (HttpURLConnection) uflconnection.openConnection();
            HttpURLConnection.setFollowRedirects(false);
            huc.setConnectTimeout(15 * 1000);
            huc.setRequestMethod("GET");
            huc.connect();
            InputStream input = huc.getInputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(input));
            String inputLine;

            while ((inputLine = in.readLine()) != null) {
                if (!(inputLine.startsWith("S") || inputLine.startsWith("s"))) {
                    String[] fields = inputLine.split(",");

                    int M = Integer.parseInt(fields[3]);
                    int D = Integer.parseInt(fields[4]);
                    int a = (14 - M) / 12;
                    int y = Integer.parseInt(fields[2]) + 4800 - a;
                    int m = M + 12 * a - 3;

                    long JD = D + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;

                    String tempDate = String.format("%05d",
                            Integer.parseInt(fields[2].substring(2)) * 1000 + Integer.parseInt(fields[5]));
                    String SRad;
                    if (fields[13].length() > 1) {
                        SRad = String.format("%.1f", Double.parseDouble(fields[13]));
                    } else {
                        SRad = "";
                    }
                    String TMax = String.format("%.1f", Double.parseDouble(fields[9]));
                    String TMin = String.format("%.1f", Double.parseDouble(fields[8]));
                    String RAIN = String.format("%.1f", Double.parseDouble(fields[12]));
                    String RHUM = String.format("%.1f", Double.parseDouble(fields[11]));
                    String WIND = String.format("%.1f", Double.parseDouble(fields[14]));
                    String TDEW = String.format("%.1f", Double.parseDouble(fields[10]));
                    String PAR = "";

                    String line = String.format("%5s %5s %5s %5s %5s %5s %5s %5s", tempDate, SRad, TMax, TMin,
                            RAIN, RHUM, WIND, TDEW);
                    pr.println(line);

                }
            }
            in.close();

        } catch (MalformedURLException me) {
            me.printStackTrace();
            //return 21.4;
        } catch (Exception e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    } finally {

        if (pr != null) {
            pr.close();
        }
    }

}