久久久久久久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:獲取當前星期幾的值)
主站蜘蛛池模板: 久久精品国产亚洲 | 免费观看成人性生生活片 | 成人在线黄色 | 午夜天堂精品久久久久 | 亚洲午夜av久久乱码 | 免费精品视频一区 | 日韩视频中文字幕 | 久久久久久久久久久丰满 | 午夜久久久 | 精品国产乱码一区二区三区 | 一级特黄在线 | 亚洲最色视频 | 久久久蜜桃一区二区人 | 国产成人网 | 亚洲成人福利 | 久草视频在线播放 | 曰韩一二三区 | 久久午夜国产精品www忘忧草 | 欧美性a视频 | 成人福利网站 | 中文在线视频观看 | 免费观看一级特黄欧美大片 | 美女国内精品自产拍在线播放 | 毛片久久久| 久综合 | 国内精品久久久久 | 亚洲一区二区三区免费观看 | 久久久久久久久久久福利观看 | 久久久精品网 | 日韩av成人 | 亚洲午夜精品在线观看 | 黄色成人在线观看 | 精品视频在线一区 | 免费看的黄网站 | 欧美a在线看 | 久久久高清 | 国产精品成人一区二区三区 | 久久伊人精品 | 欧美午夜视频 | 日韩午夜 | 中国大陆高清aⅴ毛片 |