I'm trying to program an android app that show's the current week_of_the_year but haven't found anything similar to what I want, I've seen the date picker but that doesn't show the week numbers and I've also been on android developer site.
So is there any way to view the current week_of_the_year in a really simple way?
If there's anyone who can show me this I'll be greatly appreciated.
new GregorianCalendar().get(Calendar.WEEK_OF_YEAR);
This should give you the current week in the current time zone. If you need it for a specific date, there are alternate constructors for GregorianCalendar.
The easiest way to do this on Android is probably to use the Time class:
int currentWeek = new Time().getWeekNumber();
Related
I need a Date picker to be able to set it's time types(Gregorian,Jalali or Hijiri)from setting and change it to each others too... and all the items that work by DATE will get new value...as I didn't have found any library to do this i tried to ask best Coders to help me by their libraries...if your answer is yes then how is possible to change all the dates by changing the type of calendar?
some one said "use joda time Library" but there is no tutorial.is joda time Ok?
پی نوشت : please comment up if you have same BROBLEM...to ANSWER]أۀ(in fa) sooner
Community,
Basically I'm working on my own Calendar App. Its a private Project to add specific functions and I wont use for example s-planner, Calendar and so on.
The Google Calendar is a great choice in my opinion but I want to learn the basics by myself.
I just started a few days ago and here we go:
The App needs 4.4 Kitkat and above versions. I started with a basic calendar view, looking like this:
So it should be possible to add Events and Reminders. It is possible to check which date is selected and working with a Date Tim Picker dialog? Or should I create an GridView and fill it. Maybe that way:
Just use the calendar api and create an Instance like this:
Calendar calendar = GregorianCalendar.getInstance();
But there is for example, no function which gives me the Dates of a Month in a Array . How its possible to fill it.
I just looked for some examples :
https://www.toptal.com/android/android-customization-how-to-build-a-ui-component-that-does-what-you-want
Is this necessary? Maybe there is an easy way. I don't understand the Calendar Api.
The Logic behind the calendar could be organized with the CalendarContract.
For example:
Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(calIntent);
So that's not the case now.
I just want to know how I can create the calendar structure and display it. Maybe a hint which way is possible to display dates of another Month ( for example: the first November 2016 = Tuesday so i should display the 31.10 too)
I guess there are a lot of information that I miss at this time. Hope some of you can help me. I'm sorry for my English, it isn't the best but you should understand the point. Have a great Day.
Its also my first post here, so let me know which information is missing or what I should reformat.
Are you looking for something like this. This is a fully customised calendar where you can add events to dates , can listen to date change etc :
https://github.com/khetanrajesh/CustomCalendar
I am currently trying to work with Location updating.
I've been using the below to work out the time-stamps of when the last update was processed:
String NewLocationTime = DateFormat.getTimeInstance().format(new Date());
However, to work out the difference between two times, I needed to parse it to a Time format. However, for some reason the Android Studio didn't recognize the DateTimeFormatter, and because I don't know in what format the String is going to come up, I am not quite sure what to put in the formatting either.
I believe it would be much easier if I was to be able to get a Time object straight away, so I can use something like:
long diffInMinutes = java.time.Duration.between(dateTime1, dateTime2).toMinutes();
Can anyone tell me how I get the Time object straight away, or why the Android Studio does not recognize the DateTimeFormatter?
Thank you
Use new Date().getTime() and what you get is the time in milliseconds and you can work with it as you want.
You need to use Date and use Date.getTime() for difference calculation. I do though recommend Joda-Time.
Also look at Calendar.
Time an sql aware wrapper around Date and there is no such thing as DateTime or DateTimeFormatter.
This is very simple, I would expect the following piece of code to display Gennaio (Italian for January) but it still displays January. Even if I set the device locale to Italy. Any help will be appreciated. Thanks,W.
Calendar calendar= Calendar.getInstance(Locale.ITALIAN);
calendar.set(2011,0,1);
button.setText((calendar.getTime().toString()));
Your conclusion is logical but toString() is usually and certainly in this case a utility function, meant mainly for debugging.
For localised dates you need to use a DateFormatter, like so:
Calendar calendar=Calendar.getInstance();
calendar.set(2011,0,1);
String formatted=DateFormat.getLongDateFormat(this).format(calendar.getTime());
button.setText(formatted);
This example uses one of the three standard date formatters but you can get quite specific about the format, particularly be calling DateFormat.getInstance(context).getDateInstance which allows you to set more parameters, including the locale.
There's a litte more detail here: http://developer.android.com/reference/java/text/DateFormat.html
I hope that's what you were looking for.
I am new in Android.I can't find any way to calculate the time difference.So please help me. I designed a simple application. In this program I took 3 EditTexts and in these EditText I want to input the login time and logout time then store these values in the Database, And in the 3rd EditText I want to display the difference between these two time.
You can use standard Java api calls:
System.nanoTime()
System.currentTimeMillis()
Also, check out these two links for calculating time difference.
An easier approach -
Date interestingDate = new Date();
different in milliseconds between the actual current date and interestingDate by doing:
(new Date()).getTime() - interestingDate.getTime();
Check the referenced answer in this link.