내 앱에서 이번 주에 사용자가 가지고있는 약속 목록을 표시하고 싶습니다. API에 전달할 인수는 fromDate 및 toDate (밀리 초)입니다. 나는 그 주 마지막 날의 밀리 세컨드 단위로 날짜를 얻는 법을 배워야한다. (주일은 일요일부터 시작하여 토요일까지 끝난다.)다음 토요일의 날짜를 밀리 초 (long)로 가져옵니다.
0
A
답변
0
// get today and clear time of day
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
cal.clear(Calendar.MINUTE);
cal.clear(Calendar.SECOND);
cal.clear(Calendar.MILLISECOND);
// get start of this week in milliseconds
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
System.out.println("Start of this week: " + cal.getTime());
System.out.println("... in milliseconds: " + cal.getTimeInMillis());
// start of the next week
cal.add(Calendar.WEEK_OF_YEAR, 1);
System.out.println("Start of the next week: " + cal.getTime());
System.out.println("... in milliseconds: " + cal.getTimeInMillis());
주말 마지막 날에 6을 더하십시오 !!
0
일주일의 첫 번째 요일을 일요일로 추가 한 다음 6 일을 더하면됩니다.
// Get current time. You can reset hours/ minutes/ seconds it with default values which you want.
Calendar c = new GregorianCalendar(Locale.getDefault());
// Set first day of week
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
// Add 6 into that to get Saurday
c.add(Calendar.DAY_OF_WEEK, 6);
// Get millisenconds for Saturday
long millies = c.getTimeInMillis();
0
다가오는 토요일을 밀리 초 단위로 확인하려면 아래 코드를 확인하십시오.
public class NextSaturdayMain
{
public static void main(String[] args)
{
System.out.println(getSaturday(new Date()));
}
public static long getSaturday(Date today)
{
Calendar cal = Calendar.getInstance();
cal.setTime(today);
int dow = cal.get(Calendar.DAY_OF_WEEK);
while (dow != Calendar.SATURDAY) {
int date = cal.get(Calendar.DATE);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
if (date == getMonthLastDate(month, year)) {
if (month == Calendar.DECEMBER) {
month = Calendar.JANUARY;
cal.set(Calendar.YEAR, year + 1);
} else {
month++;
}
cal.set(Calendar.MONTH, month);
date = 1;
} else {
date++;
}
cal.set(Calendar.DATE, date);
dow = cal.get(Calendar.DAY_OF_WEEK);
}
System.out.println(cal.getTime());
return cal.getTimeInMillis();
}
private static int getMonthLastDate(int month, int year)
{
switch (month)
{
case Calendar.JANUARY:
case Calendar.MARCH:
case Calendar.MAY:
case Calendar.JULY:
case Calendar.AUGUST:
case Calendar.OCTOBER:
case Calendar.DECEMBER:
return 31;
case Calendar.APRIL:
case Calendar.JUNE:
case Calendar.SEPTEMBER:
case Calendar.NOVEMBER:
return 30;
default: // Calendar.FEBRUARY
return year % 4 == 0 ? 29 : 28;
}
}
}
+2
여기에 게시 된 것 이상을 추가하지 않아 귀하의 웹 사이트 링크를 제거했습니다. [자신의 블로그를 홍보하는 것이 허용됩니까?] (https://meta.stackoverflow.com/questions/273209/is-it-acceptable-to-promote-your-own-blog) 및 [하지 않는 방법]을 읽어보십시오. 스패머] (https://stackoverflow.com/help/promotion) – adiga
관련 문제
- 1. 자바 스크립트에서 날짜를 밀리 초 단위의 밀리 초 단위로 변환합니다.
- 2. 날짜를 밀리 초 단위로 변환
- 3. Objective-C에서 다음 토요일의 날짜를 받으시겠습니까?
- 4. Excel에서 날짜를 밀리 초 단위로 복사
- 5. 밀리 초 단위의 정확한 날짜를 C#
- 6. JSTL을 사용하여 날짜를 밀리 초 단위로 변환합니다.
- 7. 밀리 초 날짜를 DateTime으로 변환하는 방법은 무엇입니까?
- 8. bc없이 밀리 초 시간 (밀리 초 단위)
- 9. , 초, 밀리 초, 마이크로
- 10. (밀리 초)
- 11. 밀리 초
- 12. datetime을 밀리 초 정밀도와 비교하십시오.
- 13. nodejs 그래서 밀리 초
- 14. 다음 5 초까지 밀리 초 15 분
- 15. 밀리 초 단위의 SimpleDateFormat
- 16. 자바 스크립트 날짜 + 밀리 초
- 17. 밀리 초 또는 날짜 유형?
- 18. 밀리 초 단위로 날짜를 저장하고 Java에서 콜렉션을 사용하여 정렬하는 방법
- 19. Android Chronometer로 밀리 초 표시 (밀리 초 단위로 표시)
- 20. 10 진수 밀리 초 단위의 밀리 초 변환
- 21. Android - SMS 시간 기록에서 밀리 초 단위로 날짜 시간을 가져옵니다.
- 22. 밀리 초 타이밍 C++
- 23. 에포크에서 밀리 초 계산하기
- 24. mp3 길이 (밀리 초)
- 25. Excel에서 밀리 초 표시
- 26. 밀리 초 단위의 NetStream.seek
- 27. C++, 타이머, 밀리 초
- 28. ehCache setTimeToLive (밀리 초)
- 29. POSIXct 클래스의 밀리 초
- 30. 어떻게하고 있어요 밀리 초
어떤 국가에서 사용할 수 있습니까? –
@MehulKanzariya 예. Locale.getDefault()를 사용하면됩니다. 그리고 특정 국가를 원할 경우 'Locale.US'또는 'Locale.CANADA'등을 사용할 수 있습니다. –