JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 使用Calendar 算出這個月有幾週
chuang5089





發文: 253
積分: 0
於 2008-08-29 00:53 user profilesend a private message to usersend email to chuang5089reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
個位我在Calendar 這個API上有一個參數是
getActualMaximum(Calendar.WEEK_OF_MONTH) , 透過這個參數我可以知道 ,在這個月有幾週
假設今天是2008/08/29 = 第5週 , 然後要我改變日期為 2008/08/13 會等於這個月的第3週,

請問一下在程式上有那一種API 可以讓我輸週數後可以知道這一週的第一天的日期是幾號謝謝.

Calendar cal   = Calendar.getInstance();
int weeeklist   = cal.getActualMaximum(Calendar.WEEK_OF_MONTH);
= 週數


reply to postreply to post
http://blog.yam.com/javanull/
作者 Re:使用Calendar 算出這個月有幾週 [Re:chuang5089]
hkdennis2k





發文: 1926
積分: 6
於 2008-08-29 00:57 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
set 和 get

reply to postreply to post
1. Programming is not coding

2. Learning Java is not leaning Java syntax

3. Study, not wait for be taught

4. Answer to yourself, not ask somebody else

5. Code is poetry

---
6. 我跑去寫 C# 了....

---
7. 回到 Java, PHP 還有 servers farm
---
8. 很久沒有寫 Java 了, 倒
作者 Re:使用Calendar 算出這個月有幾週 [Re:hkdennis2k]
chuang5089





發文: 253
積分: 0
於 2008-08-29 01:06 user profilesend a private message to usersend email to chuang5089reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問要在那做 set and get ?
請指教一下謝謝


reply to postreply to post
http://blog.yam.com/javanull/
作者 Re:使用Calendar 算出這個月有幾週 [Re:chuang5089]
Duncan

還隱隱作痛

版主

發文: 7814
積分: 39
於 2008-08-29 01:17 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
chuang5089 wrote:
請問要在那做 set and get ?
請指教一下謝謝


http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#set(int,%20int)
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Calendar.html#get(int)


Duncan edited on 2008-08-29 01:19
reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:使用Calendar 算出這個月有幾週 [Re:chuang5089]
chuang5089





發文: 253
積分: 0
於 2008-08-29 01:38 user profilesend a private message to usersend email to chuang5089reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
對不起我想我說的不是很清楚 , 我的意思是當我使用

Calendar cal = Calendar.getInstance();
int weeeklist = cal.getActualMaximum(Calendar.WEEK_OF_MONTH);
會知道System.out.println(weeeklist) = 6 週.

2008/08/29 = 這個月的第5週,要是我在程式上輸出 第2週時我要怎樣知道在第2週的星期日是幾號

謝謝


reply to postreply to post
http://blog.yam.com/javanull/
作者 Re:使用Calendar 算出這個月有幾週 [Re:chuang5089]
worookie

Small Ship

版主

發文: 2092
積分: 21
於 2008-08-29 01:46 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
chuang5089 wrote:
對不起我想我說的不是很清楚 , 我的意思是當我使用

Calendar cal = Calendar.getInstance();
int weeeklist = cal.getActualMaximum(Calendar.WEEK_OF_MONTH);
會知道System.out.println(weeeklist) = 6 週.

2008/08/29 = 這個月的第5週,要是我在程式上輸出 第2週時我要怎樣知道在第2週的星期日是幾號

謝謝


慢慢算就好了
要有耐心


reply to postreply to post
作者 Re:使用Calendar 算出這個月有幾週 [Re:chuang5089]
Duncan

還隱隱作痛

版主

發文: 7814
積分: 39
於 2008-08-29 03:20 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
chuang5089 wrote:
對不起我想我說的不是很清楚 , 我的意思是當我使用

Calendar cal = Calendar.getInstance();
int weeeklist = cal.getActualMaximum(Calendar.WEEK_OF_MONTH);
會知道System.out.println(weeeklist) = 6 週.

2008/08/29 = 這個月的第5週,要是我在程式上輸出 第2週時我要怎樣知道在第2週的星期日是幾號

謝謝


1
2
3
4
5
6
    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.set(2008, 7, 1); // 2008-08-01,調整到目標年份與月份
    cal.set(java.util.Calendar.WEEK_OF_MONTH, 2); // 調整成第二週
    cal.set(java.util.Calendar.DAY_OF_WEEK, java.util.Calendar.SUNDAY); // 調整成星期日
    System.out.println("Now the date is " + cal.getTime());
    int day = cal.get(java.util.Calendar.DATE);


Duncan edited on 2008-08-29 03:24
reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:使用Calendar 算出這個月有幾週 [Re:hkdennis2k]
chuang5089





發文: 253
積分: 0
於 2008-08-29 14:55 user profilesend a private message to usersend email to chuang5089reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
謝謝 Duncan

reply to postreply to post
http://blog.yam.com/javanull/
» JWorld@TW »  Java SE 討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8