android studio where does the calendar get the time from - java

I have an old android phone with no SIM card that I want to use to test smaller screens with my timecard app, what I'm wondering is, where does the calendar method,
For example:
Calender now = Calendar.getInstance()
get the time from? A server or does it get the time data directly from the android cellphone?

The method getInstance returns a calendar whose locale is based on system settings and whose time fields have been initialized with the current date and time.
https://developer.android.com/reference/java/util/Calendar.html

Related

Getting epoch time from calendar view in android

i need to get the epoch time in milliseconds of the date selected by the user from my calendar view. I use the metod calendarView.getDate() and I pass the result in my retrofit request. When I get the date back and set it as date in the view using calendarView.setDate(milliseconds) the calendar goes to dates like the '70s and if i take the number and convert it into date format using a simple python program or an online converter it gives me like if it is 2030.
I tried to set the minDate of the calendar view to 01/01/1970 but it didn't changed. I won't share my code because i just used the two methods i said.
Thank you for helping me

Change link to download every 7 days?

I'm downloading a certain website in html format to my device, so that I can display it in webview in offline mode. The only problem is that the link is dynamic, and it changes once a week. To keep the html item updated as much as possible, I want the app to download it once a week.
Let's say for example that this is the websites address:
www.mywebsite.com/1
Next week, the address will be:
www.mywebsite.com/2
And week after that, the website will be:
www.mywebsite.com/3
I already figured I would do this be declaring a variable that would be changing, something like
int week;
String urlToDownload = "www.mywebsite.com/" + week;
But how do I make it so that this variable will change everyday even if the app is not started, or is there a better way to do this?
You can maybe use AlarmManager class. That allows you to plan something on the background, when app is not even running.
I would use the most simple solution. Do you know what time does the URL change? You can always check the time of previous start of application and when next app is started check it and determine how many weeks is from that.
Use the java.util.Calendar
Calendar calender = Calendar.getInstance();
MyLog.d("Current Week:", "" + calender.get(Calendar.WEEK_OF_YEAR));
This prints "Current Week: 37"
With that maybe you can write code to get the appropriate page. The week nr are kind of static
You can update the variable during the onStart() phase. Make a constant that has the start date, and then get the current date and figure out the offset. This way even if the app hasnt been started in a long time, once it is started you will have the proper link.

Google App Engine - GAE will not set Default TimeZone

I have tried the following so I can get Date based on my timezone which is "Africa/Johannesburg" or GMT+2:00 but Google servers always return time using its own timezone which is 2 hours behind mine.
I have done the FF:
in appengine-web.xml I have set
<property name="user.timezone" value="Africa/Johannesburg"/>
I have also tried TimeZone.setDefault(TimeZone.getTimeZone("GMT+2:00")); before creating Date object
in the init method of my servlet, I have also tried
#Override
public void init() throws ServletException {
TimeZone.setDefault(TimeZone.getTimeZone("GMT+2:00"));
}
But this thing won't just work. Because JDK date is not thread safe, I am using JodaTime, which works well, In fact when I do new DateTime(DateTimeZone.forID("Africa/Johannesburg")) I get correct time but for legacy issues, I have to store date in JDK date hence have to convert Joda to JDK Date by invoking .Date(), then the time is completely screwed up in wrong timezone.
Does anyone by chance know how to set this without having to subtract the hours difference.
You can't. The system timezone is not changeable. You should store all of your dates in unix time and convert them to a Date or Calendar object using your timezone. I also would not assume that GAE is always going to use the same timezone...
When you save any date in Datastore it will be saved in the timeZone you have set in your JVM, thats why before starting the app I always set it to UTC:
//To avoid difference of dates depending on where the server is located
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Nonetheless when you browse the datastore in the gcloud console it will be shown in your local timezone (probably it gets the browser timezone and adapts the response to you). But when you query it back the calendar date taken in count will be the one you used for saving it (In my case UTC).

Setting Alarm for different timezones using AlarmManager

My Android application needs to set a number of alarms over the next few weeks using the AlarmManager. As of now, I'm planning to hard code those date/times using an array of calendar objects.
The question I'm facing is, how do I handle different timezones? Supposing I set an alarm for
2nd August 2012 15:00 GMT , how do I make sure that a person using the app somewhere else (say India i.e. GMT+5.30) gets the alarm at 2nd August 2012 20:30
Is there a way the app can get the timezone difference (i.e. the '+5.30' part) of that particular device so that before setting the alarm, to each Calendar object I can add that difference and then set the alarm?
I would suggest you to use System.currentTimeMillis(), Which should return u the time of system depends on what timezone the phone is in

Android - Creating your own calendar

Is there away of creating a calendar app for android from scratch using java and xml in eclipse or is there an already made calendar.
A Calendar is simply a table, which you can create in Android. A TextView on top can be used for the current month. Clicking on a cell can open the list of events for that day.
Well, there are two ways to "create your own calendar".
The easy way is to create a client of google calendar or other service.
And the second is to create a client and server of your calendar.

Categories

Resources