java on the date of the operation and use instructions

2010-06-13  来源:本站原创  分类:Java  人气:208 

Operation on the date of principal can be
java.text.SimpleDateFormat
java.util.Calendar
java.util.Date
Operate, can also be used apacle commons commons-lang package in under
org.apache.commons.lang.time.DateUtils to operate on the date on the line to write some of the operations following the date of the tools

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.apache.log4j.Logger;

public class DateUtils {
    private static final Logger log = Logger.getLogger(DateUtils.class);

    /**
     *  Converts the string to a date  Date
     *
     * @param s
     * @return
     */
    public static Date convertToDate(String s) {
        DateFormat df;
        if (s == null) {
            return null;
        }
        if (s.contains(":")) {
            try {
                df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                return df.parse(s);
            } catch (Exception e) {
                log.error(e);
                return null;
            }
        } else {
            try {
                df = new SimpleDateFormat("yyyy-MM-dd");
                return df.parse(s);
            } catch (Exception e) {
                log.error(e);
                return null;
            }
        }
    }

    /**
     *  Converts the Date  String
     *
     * @param d
     * @return
     */
    public static String formatDate(Date d) {
        if (d == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.format(d);
        } catch (Exception e) {
            log.error(e);
            return null;
        }
    }

    /**
     *  Converts the Date  String
     *
     * @param d
     * @return
     */
    public static String formatTime(Date d) {
        if (d == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try {
            return sdf.format(d);
        } catch (Exception e) {
            log.error(e);
            return null;
        }
    }

    public static String formatTimeHHmm(Date d) {
        if (d == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        try {
            return sdf.format(d);
        } catch (Exception e) {
            log.error(e);
            return null;
        }
    }

    /**
     *  According to the Date  locale Converted to  String
     *
     * @param d
     * @return
     */
    public static String formatLocaleDate(Date d, Locale locale) {
        if (d == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", locale);
        try {
            return sdf.format(d);
        } catch (Exception e) {
            log.error(e);
            return null;
        }
    }

    /**
     *  According to the Date  locale Converted to  String
     *
     * @param d
     * @return
     */
    public static String formatLocaleDateTime(Date d, Locale locale) {
        if (d == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale);
        try {
            return sdf.format(d);
        } catch (Exception e) {
            log.error(e);
            return null;
        }
    }

    /**
     *  Converts the Date  String
     *
     * @param d
     * @return
     */
    public static String formatDateTime(Date d) {
        if (d == null) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            return sdf.format(d);
        } catch (Exception e) {
            log.error(e);
            return null;
        }
    }

    /**
     *  Get the number of days per month
     *
     * @param year
     * @param month
     * @return  Returns-1 indicates that the exception
     */
    public static int getDaysByMonth(int year, int month) {
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            return 31;
        }

        if (month == 4 || month == 6 || month == 9 || month == 11)
            return 30;

        if (month == 2) {
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                return 29;
            } else {
                return 28;
            }
        }
        return -1;
    }

    public static String dayOfWeekByDayNum(int x) {
        String str = " Sunday  ";
        if (x == 7) {
            str = " Sat.  ";
        } else if (x == 6) {
            str = " Fri.  ";
        } else if (x == 5) {
            str = " Thurs.  ";
        } else if (x == 4) {
            str = " Wed.  ";
        } else if (x == 3) {
            str = " Tues.  ";
        } else if (x == 2) {
            str = " Monday  ";
        }
        return str;
    }

    /**
     *  According to the month of the year.  . The day to day, get the weekday
     *
     * @param year
     * @param month
     * @param day
     * @return
     */
    public static int getWeekByDate(int year, int month, int day) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month - 1);
        c.set(Calendar.DAY_OF_MONTH, day);

        return c.get(Calendar.DAY_OF_WEEK);
    }

    /**
     *  Get now is the day of the week
     *
     * @return
     */
    public static int getWeekByDate() {
        Calendar c = Calendar.getInstance();
        return c.get(Calendar.DAY_OF_WEEK);
    }

    public static List<String> monthDiff(Date date1, Date date2) throws Exception {
        List<String> monthList = new ArrayList<String>();

        if (DateUtils.dateDiff(date1, date2) < 0) {
            return monthList;
        }

        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar1.setTime(date1);
        calendar2.setTime(date2);
        while (DateUtils.dateDiff(calendar1.getTime(), calendar2.getTime()) >= 0) {
            monthList.add(DateUtils.formatDate(calendar1.getTime()));
            calendar1.set(Calendar.DAY_OF_MONTH, 1);
            calendar1.set(Calendar.MONTH, calendar1.get(Calendar.MONTH) + 1);
        }
        if (monthList.size() > 0) {
            monthList.remove(monthList.size() - 1);
            monthList.add(DateUtils.formatDate(date2));
        }

        return monthList;
    }

    /**
     *  Compute difference between two dates of days
     *
     * @param date1
     * @param date2
     * @return
     */
    public static int dateDiff(Date date1, Date date2) {
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        calendar1.setTime(date1);
        calendar2.setTime(date2);
        long increaseDate = (calendar2.getTimeInMillis() - calendar1.getTimeInMillis()) / 1000 / 60 / 60 / 24;
        if (((calendar2.getTimeInMillis() - calendar1.getTimeInMillis()) % (1000 * 60 * 60 * 24)) > 0) {
            increaseDate = increaseDate + 1;
        }
        return (int) increaseDate;
    }

    /**
     *  Get the number of days between two days
     *
     * @param start
     * @param end
     * @return
     */
    public static int daysBetween(Date start, Date end) {
        // return date1.getTime() / (24*60*60*1000) - date2.getTime() /
        // (24*60*60*1000);
        String formatDate = formatDate(start);
        Date convertStartDate = convertToDate(formatDate);
        formatDate = formatDate(end);
        Date convertEndDate = convertToDate(formatDate);
        return (int) (convertEndDate.getTime() / 86400000 - convertStartDate.getTime() / 86400000); //  Use the number immediately, reducing the overhead of multiplication
    }

    /**
     *  Get two days between the date array, contains the start date and end date
     *
     * @param startDateStr
     *             Start date
     * @param endDateStr
     *             End date
     * @return Date[]  Date array
     */
    public static Date[] getBetweenTwoDayArray(String startDateStr, String endDateStr) {
        Date startDate = formatDateYyyyMmDd(startDateStr);
        int dateNum = Integer.parseInt(getDaysBetweenTwoDates(startDateStr, endDateStr)) + 1;
        Date[] dataArray = new Date[dateNum];
        for (int i = 0; i < dateNum; i++) {
            dataArray[i] = startDate;
            startDate = org.apache.commons.lang.time.DateUtils.addDays(startDate, 1);
        }
        return dataArray;
    }

    /**
     *  The date string is formatted as a date type
     *
     * @param datetext
     * @return
     */
    public static Date formatDateYyyyMmDd(String datetext) {
        try {
            SimpleDateFormat df;
            if (datetext == null || "".equals(datetext.trim())) {
                return null;
            }
            datetext = datetext.replaceAll("/", "-");
            df = new SimpleDateFormat("yyyy-MM-dd");
            Date date = df.parse(datetext);
            return date;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /*
     *  Between the two dates in common between days   author:jerry.ji date:08-03-06
     *
     * @param from  Starting time
     *
     * @param to  Die hard with a period of time
     *
     * @return  Number of days
     */
    public static String getDaysBetweenTwoDates(String dateFrom, String dateEnd) {
        Date dtFrom = null;
        Date dtEnd = null;
        dtFrom = string2Date(dateFrom, "yyyy-MM-dd");
        dtEnd = string2Date(dateEnd, "yyyy-MM-dd");
        long begin = dtFrom.getTime();
        long end = dtEnd.getTime();
        long inter = end - begin;
        if (inter < 0) {
            inter = inter * (-1);
        }
        long dateMillSec = 24 * 60 * 60 * 1000;

        long dateCnt = inter / dateMillSec;

        long remainder = inter % dateMillSec;

        if (remainder != 0) {
            dateCnt++;
        }
        return String.valueOf(dateCnt);
    }

    /**
     *  The date string is formatted as a date type
     *
     * @param datetext
     *             A date string
     * @param format
     *             Date format, if it is used  "yyyy-MM-dd HH:mm:ss" Format
     * @return
     */
    public static Date string2Date(String datetext, String format) {
        try {
            SimpleDateFormat df;
            if (datetext == null || "".equals(datetext.trim())) {
                return new Date();
            }
            if (format != null) {
                df = new SimpleDateFormat(format);
            } else {
                datetext = datetext.replaceAll("/", "-");
                df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            }

            Date date = df.parse(datetext);

            return date;

        }

        catch (Exception e) {
            e.printStackTrace();
            return new Date();
        }
    }

    public static String formatDate(Date date, String format) {
        try {
            if (format != null && !"".equals(format) && date != null) {
                SimpleDateFormat formatter = new SimpleDateFormat(format);
                return formatter.format(date);
            }
        } catch (Exception e) {
            return "";
        }
        return "";
    }

    /**
     *  Work out two dates in the month of
     *
     * @param fromDate
     * @param toDate
     * @return
     */
    public static Set<String> getMonthBetweenTwoDate(Date fromDate, Date toDate) {
        long begin = fromDate.getTime();
        long end = toDate.getTime();
        long inter = end - begin;
        if (inter < 0) {
            inter = inter * (-1);
        }
        long dateMillSec = 86400000;
        long dateCnt = inter / dateMillSec;
        long remainder = inter % dateMillSec;
        if (remainder != 0) {
            dateCnt++;
        }
        Set<String> set = new LinkedHashSet<String>();
        Calendar cl = Calendar.getInstance();
        cl.setTime(fromDate);
        cl.set(Calendar.HOUR_OF_DAY, 0);
        cl.set(Calendar.MINUTE, 0);
        cl.set(Calendar.SECOND, 0);
        cl.set(Calendar.MILLISECOND, 0);
        set.add(getDateyyyyMM(cl.getTime()));
        for (int i = 1; i <= dateCnt; i++) {
            cl.add(Calendar.DAY_OF_YEAR, 1);
            set.add(getDateyyyyMM(cl.getTime()));
        }
        return set;
    }

    /**
     *  Get yyyyMM years
     *
     * @param date
     * @return
     */
    public static String getDateyyyyMM(Date date) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
        return df.format(date);
    }

    /**
     *  Get yyyyMM years
     *
     * @param date
     * @return
     */
    public static String getDateyyyyMMdd(Date date) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        return df.format(date);
    }

    /**
     *  Get the maximum number of days in January
     *
     * @param date
     * @return
     */
    public static int getMonthsMaxDay(Date date) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date);
        return cal1.getActualMaximum(cal1.DAY_OF_MONTH);
    }

    public static Date parseDateyyyyMM(String month) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
        try {
            return df.parse(month);
        } catch (ParseException e) {
        }
        return null;
    }

    public static Date parseDateyyyyMMdd(String date) {
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        try {
            return df.parse(date);
        } catch (ParseException e) {
        }
        return null;
    }

    /**
     *  Based on two dates, work out a first day of the month  , Or the last day
     *
     * @param dateFrom
     * @param dateTo
     * @param month
     * @param flag
     * @return
     */
    public static int getDayBetweenDateStartOrEnd(Date dateFrom, Date dateTo, Date month, String flag) {
        if (dateFrom.getTime() > dateTo.getTime()) {
            Date temp = dateFrom;
            dateFrom = dateTo;
            dateTo = temp;
        }
        if (getDateyyyyMM(month).compareTo(getDateyyyyMM(dateFrom)) > 0
                && getDateyyyyMM(month).compareTo(getDateyyyyMM(dateTo)) < 0) {
            if ("start".equals(flag))
                return 1;
            return getMonthsMaxDay(month);
        } else if (getDateyyyyMM(month).compareTo(getDateyyyyMM(dateFrom)) == 0
                && getDateyyyyMM(month).compareTo(getDateyyyyMM(dateTo)) < 0) {
            if ("start".equals(flag))
                return getDayOfMonth(dateFrom);
            return getMonthsMaxDay(month);
        } else if (getDateyyyyMM(month).compareTo(getDateyyyyMM(dateFrom)) > 0
                && getDateyyyyMM(month).compareTo(getDateyyyyMM(dateTo)) == 0) {
            if ("start".equals(flag))
                return 1;
            return getDayOfMonth(dateTo);
        } else {
            if ("start".equals(flag))
                return getDayOfMonth(dateFrom);
            return getDayOfMonth(dateTo);
        }

    }

    /**
     *  According to a date, calculated is the month day of
     *
     * @param date
     * @return
     */
    public static int getDayOfMonth(Date date) {
        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date);
        return cal1.get(Calendar.DAY_OF_MONTH);
    }

    /**
     *  Check out a month in a day's date
     *
     * @param month
     * @param num
     * @return
     */
    public static Date getDateOfMonthByNum(String month, int num) {
        Calendar cl = Calendar.getInstance();
        cl.setTime(parseDateyyyyMM(month));
        cl.set(Calendar.HOUR_OF_DAY, 0);
        cl.set(Calendar.MINUTE, 0);
        cl.set(Calendar.SECOND, 0);
        cl.set(Calendar.MILLISECOND, 0);
        cl.add(Calendar.DAY_OF_YEAR, num - 1);
        return cl.getTime();
    }

    /**
     *  Get the date of the first day of the week
     *
     * @author vincent.shan
     * @return
     */
    public static Date getCurrentWeekMonday() {

        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        int index = cal.get(Calendar.DAY_OF_WEEK);
        //  Go into China's habit, if this is the first day  , The transformation to the seventh day  ( Sunday foreign to the first day of the week, which is the last day of the week  )
        if (index == 1)
            index = 8;
        cal.add(Calendar.DATE, -(index - 2));
        return cal.getTime();

    }

    /**
     *  Get this week's last date
     *
     * @author vincent.shan
     * @return
     */
    public static Date getCurrentWeekSaturday() {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        int index = cal.get(Calendar.DAY_OF_WEEK);
        if (index == 1)
            index = 8;
        cal.add(Calendar.DATE, -(index - 2));
        cal.add(Calendar.DATE, 6);
        return cal.getTime();
    }

    /**
     *  Move from a specified date, number of days
     *
     * @param date
     * @param day
     * @return
     */
    public static Date moveDay(Date date, int day) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DAY_OF_MONTH, day);
        return cal.getTime();
    }

    /**
     *  From today's date moves a certain number of months
     *
     * @param month
     * @return
     */

    public static Date getMoveMonthDate(int month) {
        Date nowDate = new Date();
        Calendar cl = Calendar.getInstance();
        cl.setTime(nowDate);
        cl.add(Calendar.MONDAY, month - 1);
        Date date1 = cl.getTime();
        return date1;
    }

    /**
     *  Get yesterday
     *
     * @param date
     * @param day
     * @return
     */
    public static Date getYesterday() {
        Calendar cal = Calendar.getInstance();

        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DAY_OF_MONTH, -1);
        return cal.getTime();
    }

    /**
     *  According to a date, returns the first day of the month
     *
     * @param date
     *             Any day
     * @return Date  The first day of the month
     * */
    public static Date getMonthsFirstDay(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DATE, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    /**
     *  According to a date, returns the last day of the month
     *
     * @param date
     *             Any day
     * @return Date  The first day of the month
     * */
    public static Date getMonthsLastDay(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(Calendar.DATE, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.MONTH, 1);
        cal.add(Calendar.DATE, -1);
        return cal.getTime();
    }

    public static Set<String> getDayList(Date startDate, Date endDate) {
        long begin = startDate.getTime();
        long end = endDate.getTime();
        long inter = end - begin;
        if (inter < 0) {
            inter = inter * (-1);
        }
        long dateMillSec = 86400000;
        long dateCnt = inter / dateMillSec;
        Set<String> set = new LinkedHashSet<String>();
        Calendar cl = Calendar.getInstance();
        cl.setTime(startDate);
        cl.set(Calendar.HOUR_OF_DAY, 0);
        cl.set(Calendar.MINUTE, 0);
        cl.set(Calendar.SECOND, 0);
        cl.set(Calendar.MILLISECOND, 0);
        set.add(getDateyyyyMMdd(cl.getTime()));
        for (int i = 1; i <= dateCnt; i++) {
            cl.add(Calendar.DAY_OF_YEAR, 1);
            set.add(getDateyyyyMMdd(cl.getTime()));
        }
        set.add(getDateyyyyMMdd(endDate));
        return set;
    }

    /**
     *  Function  : Obtain a minimum of date, if the two date parameters are  null Returns  null
     *
     * @author irvshan
     *
     * @param date1
     * @param date2
     * @return Date or null
     */
    public static Date getMinimizeDate(Date date1, Date date2) {
        if (date1 == null) {
            return date2;
        }
        if (date2 == null) {
            return date1;
        }
        if (date1.compareTo(date2) > 0) {
            return date2;
        }
        return date1;
    }

    /**
     *  Function  : To obtain a maximum date, if the two date parameters are  null Returns  null
     *
     * @author irvshan
     *
     * @param date1
     * @param date2
     * @return Date or null
     */
    public static Date getMaxmizeDate(Date date1, Date date2) {
        if (date1 == null) {
            return date2;
        }
        if (date2 == null) {
            return date1;
        }
        if (date1.compareTo(date2) < 0) {
            return date2;
        }
        return date1;
    }

    public static int getDayofWeek(Date date, int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + day - 1);
        return calendar.get(Calendar.DAY_OF_WEEK);
    }

    /**
     *  The date1 hour  , Minutes, seconds into  date2 The hour, minute  , Second, returns a value of  date1
     *
     * @param date1
     * @param date2
     * @return
     */
    public static Date changeTheHourMinuteSecond(Date date1, Date date2) {
        Calendar cl1 = Calendar.getInstance();
        cl1.setTime(date1);
        cl1.set(Calendar.HOUR_OF_DAY, 0);
        cl1.set(Calendar.MINUTE, 0);
        cl1.set(Calendar.SECOND, 0);

        Calendar cl2 = Calendar.getInstance();
        cl2.setTime(date2);
        cl1.set(Calendar.HOUR_OF_DAY, cl2.get(Calendar.HOUR_OF_DAY));
        cl1.set(Calendar.MINUTE, cl2.get(Calendar.MINUTE));
        cl1.set(Calendar.SECOND, cl2.get(Calendar.SECOND));

        return cl1.getTime();
    }

    public static void main(String[] args) {

    }

}
相关文章
  • java on the date of the operation and use instructions 2010-06-13

    Operation on the date of principal can be java.text.SimpleDateFormat java.util.Calendar java.util.Date Operate, can also be used apacle commons commons-lang package in under org.apache.commons.lang.time.DateUtils to operate on the date on the line to

  • java.sql.SQLException: ResultSet not open, operation 'next' not permitted. 2010-09-27

    java.sql.SQLException: ResultSet not open, operation 'next' not permitted. Verify that autocommit is OFF. Error Translation: result set is not open, next operation are not allowed. Make sure that auto-commit is turned off. Recently encountered this e

  • Java: calculating a date with the specified number of days (excluding Saturdays, Sundays and a series of festivals) 2010-11-20

    Work experience, wrote a casual welcome to master Comments: Core code: package www.sjjjob.com.date; import java.util.ArrayList; import java.util.Calendar; import java.util.List; / ** * Date of public functions * @ Author shenjunjie * @ Version [s001,

  • java string 转date方法如何实现 2013-11-16

    在开发应用中经常会使用到java string 转date这种不是很常见的做法,本文将以此问题提供详细解决方案,需要了解的朋友可以参考下 针对JSON 返回String 类型 两次格式化就行了,例如: Java代码 String s = "2012-08-25"; SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf2 = new SimpleDateForm

  • java 时间戳和Date相互装换 2014-07-02

    java 时间戳和Date相互装换 package com.playtogether.utils; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateUtils { /** * unix时间戳转换为dateFormat * * @param beginDate * @return */ public static String ti

  • Java date and time operation function code list 2010-04-03

    /** Date Class * @date * @version 1.0 */ import java.util.*; import java.text.*; import java.util.Calendar; public class VeDate { /** * Get current time * * @return Return time type yyyy-MM-dd HH:mm:ss */ public static Date getNowDate() { Date curren

  • The JAVA interface to HDFS instance API operation 2011-05-03

    2010-6-2 20:55 Operating environment: Hadoop.0.20.2 CentOS 5.4 java version "1.6.0_20-ea" Hadoop is a stand-alone configuration of the environment I look at the operation under the screenshot The main reference of this article http://myjavanoteb

  • java string formatted date numbers Daquan 2011-09-05

    In C, you can use a similar printf ("% d% 8.2f \ \ n", 1001, 52.335) of the method to format the output, but in Java System.out.println () does not correspond to the function. To format the output, you must use the classes in the java.text packa

  • JAVA files and folders on the operation of 2010-03-29

    Read the text of the document /** * Read a text file content * @param filePathAndName With full absolute path to the file name * @param encoding Open a text file encoding * @return Returns the contents of a text file */ public String readTxt(String f

  • Java, on the date of the commonly used treatment (change) 2010-03-29

    import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; /** *//** * * @author zzk * */ public class DateUtil { /** *//** * Obtain a day together ( Reduced ) The day after the * * @param

  • java.sql the Date.Timestamp with the oracle of the date, timestamp corresponding relations 2010-04-26

    Encountered a very serious problem is to use pl / sql develop view oralce the date the statement of the field, obviously contains the date and time, but check out the data cut-only the date, time, hours, minutes and seconds are zero. And the system,

  • java on the date of the operating skills 2010-03-30

    This article is very early ... very early on deposit machine where the saw is then kept down ..... these days without reading a book on Hair's something right before the machine public class BusinessDate { public BusinessDate() { } /** * Get today's

  • java little knowledge - Date of Format 2010-03-31

    Date date=new Date(); SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(dateFm.format(date)); Date now = java.sql.Date.valueOf("2008-12-04"); System.out.println("now========" + now.toSt

  • Java String To Date Time string change 2010-04-06

    String into time format, Format ("yyyy-MM-dd hh: mm: ss") keep up the format as String date format. import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; DateFormat format= new SimpleDateFormat("yyyy-MM-dd h

  • JAVA do simple date selection dialog 2010-05-13

    package gui; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.*; import java.util.*; public class DateUI extends MouseAdap

  • The java in the Date, String, Timestamp conversion problem between 2010-06-17

    1. Access to the system current time: 1. System.out.println (new Timestamp (new java.util.Date (). GetTime)); / / contains the minutes and seconds 2. System.out.println (new java.sql.Date (new java.util.Date (). GetTime)); / / does not contain the mi

  • java code Note 2010-06-21: First, GUI, operation, complete the QQ login interface similar to the one small window. 2, is a small application JDBC: Enter name and password, enter the database to judge. 2010-06-22

    / * A cottage version of the QQ, and then relying on us an instance of class the teacher, and write their own modifications. * 1422942883 This is my QQ, welcome to the students learning to program add my friend, * Or to my personal home page message

  • Java in the Date and Timestamp 2010-08-02

    Order one: Here's an article explaining my personal view is very detailed, the use of the java.sql.Date still puzzled look. java.sql.Date stores only date data is not stored time data / / Time data will be lost preparedStatement.setDate (1, new java.

  • Summarize the Oracle database on the date of the operation 2010-11-08

    Oracle on the date of operation is quite flexible, before a brief summary of the time, only the most commonly used to write out some of this increase collected from the network statement. --1. In the system time based on the delay of 5 seconds select

  • oracle date methods of operation 2010-09-01

    There are a lot of the oracle date functions, such as: 1, add_months () from a date value for the increase or decrease the number of months date_value: = add_months (date_value, number_of_months) Example: SQL> select add_months (sysdate, 12) "Next