久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Android 日歷:更改一周的開始日期

Android Calendar: Changing the start day of week(Android 日歷:更改一周的開始日期)
本文介紹了Android 日歷:更改一周的開始日期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我有一個小問題,我正在開發一個應用程序,我需要將一周的開始日期從星期一更改為另一個(星期四、星期六).這在android中可能嗎,我需要計算一周的開始和知道日期的結束.(例如一周從星期四開始)

i have a little problem, i'm developing an application, and i need to change the start day of the week from monday to another one (thursday, of saturday). is this possible in android, i need to calculate the start to week and its end knowing the date. (the week starts ano thursday as example)

注意:我只是 android 開發的初學者.這是我的代碼SimpleDateFormat dateformate = new SimpleDateFormat("dd/MM");

Note: i'm just a beginner in android development. here is my code SimpleDateFormat dateformate = new SimpleDateFormat("dd/MM");

// get today and clear time of day
Calendar cal = Calendar.getInstance();

// get start of this week in milliseconds
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
cal.add(Calendar.DAY_OF_YEAR, 7*(WeekIndex-1));
result = dateformate.format(cal.getTime());

cal.add(Calendar.DAY_OF_YEAR, 6 );

result=result+" - " + dateformate.format(cal.getTime());

使用上面的代碼我得到了結果,但星期一是一周的明星.

using the above code im getting the result but with monday as the star of week.

注意:我無法在結果中添加日期,因為周索引會隨著開始時間的變化而變化

Note: i can't add day to the result because week index changes with the changing of it's start

推薦答案

周日到周六的日歷日值是 1-7.getFirstDayOfWeek 根據使用的 Locale 返回其中一個值(通常是星期一或星期日).Calendar.getInstance 使用默認的 Locale 取決于手機的設置,在您的情況下,星期一是一周的第一天.

Calendar days have values 1-7 for days Sunday-Saturday. getFirstDayOfWeek returns one of this values (usually of Monday or Sunday) depending on used Locale. Calendar.getInstance uses default Locale depening on phone's settings, which in your case has Monday as first day of the week.

一種解決方案是使用其他Locale:

One solution would be to use other Locale:

Calendar.getInstance(Locale.US).getFirstDayOfWeek()

將返回 1,即 Calendar.SUNDAY

其他解決方案是使用選定的星期幾值,例如

Other solution would be to use chosen day of week value like

cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);

問題是,Calendar 也在 set 中使用其內部一周的第一天值.示例:

Problem is, Calendar is using its inner first day of the week value in set as well. Example:

Calendar mondayFirst = Calendar.getInstance(Locale.GERMANY); //Locale that has Monday as first day of week
mondayFirst.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
log(DateUtils.formatDateTime(context, mondayFirst.getTimeInMillis(), 0));
//prints "May 19" when runned on May 13

Calendar sundayFirst = Calendar.getInstance(Locale.US); //Locale that has Sunday as first day of week
sundayFirst.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
log(DateUtils.formatDateTime(context, sundayFirst.getTimeInMillis(), 0));
//prints "May 12" when runned on May 13

如果您不想使用 Locale 或者您需要其他日期作為一周的第一天,最好自己計算一周的開始時間.

If you don't want to use Locale or you need other day as the first day of the week, it may be best to calculate start of the week on your own.

這篇關于Android 日歷:更改一周的開始日期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 91xxx在线观看 | 91成人免费看 | 日韩福利在线观看 | 亚洲精品免费在线 | 日韩精品视频在线 | 亚洲欧美综合精品另类天天更新 | 欧美午夜久久 | 国产精品久久久久久久久久久免费看 | 色毛片| 高清视频一区二区三区 | 国产精品小视频在线观看 | 中文字幕免费在线 | 色呦呦在线 | 久久精品99久久 | 欧洲色综合 | 国产美女一区二区三区 | 亚洲欧美视频一区 | 国产一区二区三区高清 | 久久精品免费看 | 国产东北一级毛片 | 国产99视频精品免视看9 | 亚洲精品自拍视频 | 久草在线| 久久四虎| 农村真人裸体丰满少妇毛片 | 久久人爽爽人爽爽 | 中文字幕三区 | 国产乱人伦精品一区二区 | av片在线免费看 | 久久久久亚洲国产| 国产精品久久久久无码av | 99国产精品99久久久久久 | 黄色毛片免费看 | 欧洲一级毛片 | 亚洲综合字幕 | 一区二区激情 | 欧美www在线观看 | 国产精品久久影院 | 久久精品亚洲 | 欧美性大战久久久久久久蜜臀 | 欧美一区二区三区高清视频 |