<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    春風博客

    春天里,百花香...

    導航

    <2008年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    統計

    公告

    MAIL: junglesong@gmail.com
    MSN: junglesong_5@hotmail.com

    Locations of visitors to this page

    常用鏈接

    留言簿(11)

    隨筆分類(224)

    隨筆檔案(126)

    個人軟件下載

    我的其它博客

    我的鄰居們

    最新隨筆

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    動態生成日歷

    package com.sitinspring.datetime;

    import java.util.ArrayList;
    import java.util.List;


    public class MonthlyCalendar{
        
    private static final String tab = "\t";

        
    // 日歷的年月
        private String yearMonth;
        
        
    // 一個年月的日期
        private List<String> days;
        
        
    public MonthlyCalendar(String yearMonth){
            
    this.yearMonth=yearMonth;
            fillDays();
        }

        
        
    private void fillDays(){
            days
    =new ArrayList<String>();
            
            
    // 每個月第一日前的空白
            int spacesBeforeFirstDay=DateTimeUtil.getWeekOfFirstDay(yearMonth);
            
    for(int i=0;i<spacesBeforeFirstDay;i++){
                days.add(tab);
            }

            
            
    // 每個月的日期
            int dayCountInaMonth=DateTimeUtil.getDaysInAMonth(yearMonth);
            
    for(int i=0;i<dayCountInaMonth;i++){
                days.add((i
    +1)+tab);
            }
            
        }

        
        
    public String getText(){
            StringBuffer sb
    =new StringBuffer();
            
            sb.append(
    "==="+yearMonth+"===\r\n");
            sb.append(
    "--------------------------------------------------\r\n");
            
    for(int i=0;i<days.size();i++){
                sb.append(days.get(i));
                
    if((i+1% 7==0){
                    sb.append(
    "\r\n");
                }

            }

            sb.append(
    "\r\n--------------------------------------------------\r\n");
            
            
    return sb.toString();
        }

        
        
    public static void main(String[] args){
            System.out.println(
    new MonthlyCalendar("2008.8").getText());
        }

    }


    package com.sitinspring.datetime;

    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.IOException;

    public class CalendarMaker {
        
    public CalendarMaker(int year) {
            
    this(String.valueOf(year));
        }


        
    public CalendarMaker(String year) {
            
    // 生成日歷文件
            makeFile(year);
        }


        
    private void makeFile(String fileName) {
            
    try {
                BufferedWriter out 
    = new BufferedWriter(new FileWriter(fileName
                        
    + ".txt"));

                
    for (int i = 1; i < 13; i++{
                    out.write(
    new MonthlyCalendar(fileName + "." + i).getText()); // 將字符串“內容”寫入文件
                }


                out.close();
            }
     catch (IOException e) {
                e.printStackTrace();
            }

        }


        
    public static void main(String[] args) {
            
    new CalendarMaker(2008);
        }

    }


    package com.sitinspring.datetime;

    import java.text.Format;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;

    /**
     * 日期時間處理實用類
     * 
     * 
    @author sitinspring(junglesong@gmail.com)
     * 
    @since 2008-7-18 上午10:30:15
     * @vsersion 1.00 創建 sitinspring 2008-7-18 上午10:30:15
     
    */

    public final class DateTimeUtil {
        
    private DateTimeUtil() {

        }


        
    /**
         * 以格式format返回表示日期時間的字符串
         * 
         * 
    @param format
         * 
    @return
         
    */

        
    public static String getDateTimeStr(String format) {
            Date date 
    = new Date();
            Format formatter 
    = new SimpleDateFormat(format);
            
    return formatter.format(date);
        }


        
    /**
         * 取得當前日期時間
         * 
         * 
    @return
         
    */

        
    public static String getCurrDateTime() {
            
    return getDateTimeStr("yyyy.MM.dd HH:mm:ss");
        }


        
    /**
         * 取得當前日期,不足兩位前補零
         * 
         * 
    @return
         
    */

        
    public static String getCurrDate() {
            
    return getDateTimeStr("yyyy.MM.dd");
        }


        
    /**
         * 取得當前日期
         * 
         * 
    @return
         
    */

        
    public static String getSimpleCurrDate() {
            
    return getDateTimeStr("yyyy.M.d");
        }


        
    /**
         * 取得當前時間
         * 
         * 
    @return
         
    */

        
    public static String getCurrTime() {
            
    return getDateTimeStr("HH:mm:ss");
        }


        
    /**
         * 取得當前年月
         * 
         * 
    @return
         
    */

        
    public static String getCurrYearMonth() {
            
    return getDateTimeStr("yyyy.MM");
        }


        
    /**
         * 從文本形式日期取得Date日期時間
         * 
         * 
    @param strMonth
         * 
    @return
         
    */

        
    private static Date getDate(String strMonth) {
            SimpleDateFormat myFormatter 
    = new SimpleDateFormat("yyyy.MM.dd");

            
    try {
                java.util.Date date 
    = myFormatter.parse(strMonth);
                
    return date;
            }
     catch (Exception ex) {
                
    return null;
            }

        }


        
    /**
         * 得到兩個文本日期之間的天數
         * 
         * 
    @param startDate
         * 
    @param endDate
         * 
    @return
         
    */

        
    public static long getDaysBetween(String startDate, String endDate) {
            Date dStart 
    = getDate(startDate);
            Date dEnd 
    = getDate(endDate);

            
    return (dEnd.getTime() - dStart.getTime()) / (24 * 60 * 60 * 1000);
        }


        
    /**
         * 取某月的天數,strMonth的格式是"yyyy.MM"
         * 
    @param strMonth
         * 
    @return
         
    */

        
    public static int getDaysInAMonth(String strMonth) {
            String[] arr 
    = strMonth.split("[.]");

            
    // Create a calendar object of the desired month
            Calendar cal = new GregorianCalendar(Integer.parseInt(arr[0]), Integer
                    .parseInt(arr[
    1]) - 11);

            
    // Get the number of days in that month
            int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

            
    return days;
        }


        
    /**
         * 取某月第一天是周幾,strMonth的格式是"yyyy.MM"
         * 
    @param strMonth
         * 
    @return
         
    */

        
    public static int getWeekOfFirstDay(String strMonth) {
            String[] arr 
    = strMonth.split("[.]");

            Calendar xmas 
    = new GregorianCalendar(Integer.parseInt(arr[0]), Integer
                    .parseInt(arr[
    1]) - 11);
            
    int dayOfWeek = xmas.get(Calendar.DAY_OF_WEEK) - 1;
            
    return dayOfWeek;
        }


        
    public static void main(String[] args) {
            System.out.println(
    "當前日期時間為:" + getCurrDateTime());
            System.out.println(
    "當前日期為:" + getCurrDate());
            System.out.println(
    "當前日期為:" + getSimpleCurrDate());
            System.out.println(
    "當前時間為:" + getCurrTime());
            System.out.println(
    "2008.07.05與2008.07.18之間相隔:"
                    
    + getDaysBetween("2008.07.05""2008.07.18"+ "");
            System.out.println(
    "當前年月為:" + getCurrYearMonth());
            System.out.println(
    "本月第一天為周" + getWeekOfFirstDay(getCurrYearMonth()));
            System.out.println(
    "本月有" + getDaysInAMonth(getCurrYearMonth()) + "");
        }

    }


    posted on 2008-07-19 22:14 sitinspring 閱讀(1083) 評論(0)  編輯  收藏 所屬分類: Java API

    sitinspring(http://m.tkk7.com)原創,轉載請注明出處.
    主站蜘蛛池模板: 亚洲一级特黄特黄的大片| 亚洲国产高清美女在线观看| 亚洲成AV人片高潮喷水| 波多野结衣中文字幕免费视频| 亚洲精品网站在线观看你懂的| 69pao强力打造免费高清| 亚洲精品偷拍无码不卡av| 成人免费一级毛片在线播放视频| 亚洲三级视频在线| 成人免费一区二区三区在线观看| 亚洲精品午夜国产va久久| 国产亚洲精品免费| 一级中文字幕乱码免费| 亚洲AV无码一区二区二三区入口| 2021精品国产品免费观看| 亚洲色无码国产精品网站可下载| 国产猛烈高潮尖叫视频免费| 人妻仑乱A级毛片免费看| 亚洲成年轻人电影网站www| 免费无码又黄又爽又刺激| 久久久久亚洲精品无码网址色欲| 亚洲毛片av日韩av无码| 免费人成视频在线观看网站| 国产精品亚洲片夜色在线| 亚洲av区一区二区三| 无码日韩精品一区二区免费暖暖 | 四虎永久在线精品免费一区二区| 久久久久亚洲精品无码网址 | 日韩一区二区a片免费观看| 国产成人精品久久亚洲高清不卡| 久久亚洲色一区二区三区| 91精品国产免费久久国语蜜臀| 亚洲老熟女五十路老熟女bbw| 亚洲婷婷国产精品电影人久久| 日韩精品久久久久久免费| 亚洲另类无码专区首页| 亚洲av永久无码精品古装片| 成人性生免费视频| 国产va在线观看免费| 亚洲国产成人手机在线观看 | 亚洲GV天堂无码男同在线观看|