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.
Related
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.
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 7 years ago.
Improve this question
How to get time in any post to show how much time has been gone doing this post.
For example in facebook you see the time which is passed away after your post.
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
Date past = format.parse("20/08/2015 18:10:52");
Date now = new Date();
System.out.println(TimeUnit.MILLISECONDS.toSeconds(now.getTime() - past.getTime()) + " seconds ago");
System.out.println(TimeUnit.MILLISECONDS.toMinutes(now.getTime() - past.getTime()) + " minutes ago");
System.out.println(TimeUnit.MILLISECONDS.toHours(now.getTime() - past.getTime()) + " hours ago");
System.out.println(TimeUnit.MILLISECONDS.toDays(now.getTime() - past.getTime()) + " days ago");
I'm not really sure about what you mean, giving more details would probably help.
If you want to have something like "Posted 10minutes ago", I guess you'd have to store the date/hour of the post. Then when displaying it, doing a simple operation : Time = CurrentTime - PostTime
Let's say you post something at 12:00.
You store the post with the hour
When displaying (at 12:10 for example), you substract the posted hour from the actual hour, and tchiiiing ! "Posted 10 mins ago"
You'll also have to get some work to display a difference between seconds, minutes, hours and day, but basically that's how it would work !
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 8 years ago.
Improve this question
I am developing a schedule application. I want to change image 1 to image 2 when in specific time. And is there any method to get the day of week from system.
For the second part of your question how to get the day of week from system try calendar.get() method but remember calendar.get() would return an integer based on zero index: sunday = 0 and saturday =6 and rest of the days lie in between 0 to 6.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.get(Calendar.DAY_OF_WEEK);
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.
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));