How to get all days of week using week number [closed] - android

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am confused a lot, by this thing. Actually I have developed one view pager, which is showing data week wise. I mean first screen is for current week of the year, and its related dates. Then now I swipe the screen I want next number of weeks and its dates.
i.e. For now, if current date is 2014/01/16 then current week number is 03. But now when I swipe the screen, I want 04th week dates of January.
Thanks in advance.

void getStartEndOFWeek(int enterWeek, int enterYear){
//enterWeek is week number
//enterYear is year
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(Calendar.WEEK_OF_YEAR, enterWeek);
calendar.set(Calendar.YEAR, enterYear);
SimpleDateFormat formatter = new SimpleDateFormat("ddMMM yyyy"); // PST`
Date startDate = calendar.getTime();
String startDateInStr = formatter.format(startDate);
System.out.println("...date..."+startDateInStr);
calendar.add(Calendar.DATE, 6);
Date enddate = calendar.getTime();
String endDaString = formatter.format(enddate);
System.out.println("...date..."+endDaString);
}
and also reverese
Calendar now = Calendar.getInstance();
now.set(Calendar.YEAR,2013);
now.set(Calendar.MONTH,04);//0- january ..4-May
now.set(Calendar.DATE, 04);
System.out.println("Current week of month is : " +
now.get(Calendar.WEEK_OF_MONTH));
System.out.println("Current week of year is : " +
now.get(Calendar.WEEK_OF_YEAR));

Related

Getting system date in low level API 17 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I need a way to get system date,to display in my mobile app. Minimum API level of 17 without using calendar class.
You can use the following code to get System Date, Time, TimeZone :
Date currentDate = new Date(System.currentTimeMillis());
Toast.makeText(YourActivity.this, currentDate.toString(), Toast.LENGTH_SHORT).show();
Then SPLIT your string to get DATE, TIME separately:
Hope this helps.
Get system date with Calendar class:
Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();
Get system date with Date class:
Date date = new Date();
All this classes are exist in API level 17 and higher.

How to get next day from specified date in android? [duplicate]

This question already has answers here:
How can I increment a date by one day in Java?
(32 answers)
Closed 5 years ago.
I have different dates in my program like 08-Mar-2017. How can I get next or previous date from this specified date?
Calendar cal = Calendar.getInstance();
cal.setDate(your date);
cal.add(Calendar.DAY_OF_MONTH, 1);
You have to convert the string into date and set it to calendar and then you can add a day and to remove
cal.add(Calendar.DAY_OF_MONTH, -1);

Android Current Time [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want to show current time of device in app. following is the code is getting time but problem is if current time is 12:15 but my variable cTime has opposite time that is 00:15. Below is my code for getting time, please help me out
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
Calendar c = Calendar.getInstance();
int currentHour = c.get(Calendar.HOUR);
int currentMin = c.get(Calendar.MINUTE);
String currentTime = currentHour+":"+currentMin;
Date cTime = sdf.parse(currentTime);
You should use Calendar.HOUR_OF_DAY instead of Calendar.HOUR to get the hour in 0-24 format.
Try this Code For current time
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("h:mm aa");
String datetime = sdf.format(now);
Use this simple method for get device current time in milisecound
System.currentTimeMillis();
Always, always read the documentation for the code you're using.
You are formatting your hours with the H pattern, which describes the 24 hour model:
H | Hour in day | (0-23) | Number | 0
You need to use the small h, which represents the “Hour in am/pm (1-12)”:
SimpleDateFormat format = new SimpleDateFormat("hh:mm");
Date date = new Date();
String dateReadable = format.format(date);
// Use your String elsewhere.
And this is all you need to get started. No need to create ints and Calendars for this. You can also put the a for the period indicator, as Arjun said below.
This is the foundation for this answer, too, but considering the code is slightly different and you are facing difficulties (by looking at your code), I didn't consider it a duplicate.

how to calculate the last day of the current month? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
Start up fragment I need to put in the two text two dates. Start date and end date. Start Date - the current date and I put it. End date - the last day of the current month. I do not know how to calculate. help me please.
Date start:
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
dateBegin.setText(year + "-" + (month + 1) + "-" + day);
end date, the last day of this month, I do not know how
This is what you want:
Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH);
Good luck.

How to get my device date [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to get my android device date and check with current date and compare number of days left. Tab or device doesn't have SIM also.
Thanks!
You can use this code to get the device date.
SimpleDateFormat s = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
String dateFormat = s.format(new Date(System.currentTimeMillis()));
Android API for managing times android.text.format.Time
For getting current time:
Time time = new Time();
time.setToNow();
To calculate differences between two time, you can try this code
Time time1;
Time time2;
long diff = time1.toMillis(false) - time2.toMillis(false);
// Now 'diff' contains difference between those two time in milliseconds
Update #1
This class was deprecated in API level 22.

Categories

Resources