Android: Converting a decimal number to time - android

Android
Im working on and android application that works out the time it takes to reach a destination.
what I am try to figure out is how to set up the result so the answer can be displayed as hours.minutes.seconds or days.hours.minutes.seconds.
Would I have to set up an array to get a result like this ?
or
Would the above Q be able to slip up the answer?
ie lets say I have an answer of 4.50 (been 4hrs, 30min) would I be able to take the .50 and time it by 0.6 to change the output to 4.30.
or
Can the answer be displayed in a time picker.
ps I have searched this on the forums and google etc. And I have not found and relevent, easy to comprehend answers.
pps Any codes or links would be greatly apprecated thank you.

I think you can use SimpleDateFormat class to do that.
example code:
String datastring="15.32.08"
SimpleDateFormat sf = new SimpleDateFormat("HH.mm.ss");
Date converttoData = sf.parse(datastring);
You can easily do that: First to convert a decimal to string(datastring),second,use upper code.
hope the answer can help u.:)

Related

Creating a survey in android studio

I am creating a survey in android studio. When doing the survey, I need to calculate the score when finished. How do I set the answers to a number. For example I have Strong Disagree = 1,Disagree = 2,neutral = 3,agree = 4,strongly agree = 5
Where are you saving this numbers you are getting from survey? If i understand what you are asking then you simple need to save those numbers to a variable and at the end calctulate together all of the variables.
If not then please post some code and explain the problem more specificly! Show us what you have written so far so it is easier to indentify the problem.

Add date to Events.EXDATE Android calendar provider? [duplicate]

Can someone explain how to use EXDATE when adding event to android calendar? The documentation is pretty unclear about the format in which the EXDATE should be put.
I tried many formats, these are some of them:
values.put(Events.EXDATE, "TZID=Europe/London:20130116T080000");
values.put(Events.EXDATE, "20130116T080000Z");
values.put(Events.EXDATE, "20130116T080000");
values.put(Events.EXDATE, "20130116");
but none of them works.
Any idea how to make an event not appear on a particular date, if by the RRULE it should appear?
The correct format is:
values.put(Events.EXDATE, "20130116T080000Z");
However you must ensure that it is in UTC time. I was having the same problem starting from PST, so I just had to add 8 hours to get it to work.
In addition to the #kee23's answer, the next variant is valid for multiple EXDATE values:
contentValues.put(CalendarContract.Events.EXDATE, "20130116T080000Z,20130118T080000Z");
I'm adding on top of #kee23's excellent and correct answer:
I just got aware that in android, you can not persist EXDATEs to an event with endless recurrences, say RRULE:FREQ=DAILY. You need to limit the occurrences, as in RRULE:FREQ=DAILY;COUNT=600.
This is not documented by google and there is no error message if you try to persist endless recurrences with EXDATEs. It just silently dropped RRULE and DURATION in my case.

AndroidPlot, setting different DomainValueFormats

I am trying to do the following for the x labels in my graph.
The first label should have format:
plot.getGraphWidget()
.setDomainValueFormat(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss"));
All the other labels should only show minutes and seconds:
plot.getGraphWidget()
.setDomainValueFormat(new SimpleDateFormat("mm:ss"));
I can set the Format for all labels, but I can't figure out how to change it for only the first label. My graph is dynamic and changes every second (incoming data gets updated each second with a new value).
Is there maybe a function that could help me? (It's all a bit difficult to find with website being down...) Or any other tips?
Any help is greatly appreciated.
Assuming you have no repeating values in your domain model you could keep track of your first value and test for equality inside a custom Formatter implementation. It's not pretty but because there is no way to pass in the index of the item being drawn to the Formatter that's about the only way I can see doing this.

How can I determine whether a device is using 12 or 24-hour time format?

I want to know the current device time format.
means 24 hour/ 12 hour format .
Plz let me know how can I determine that.
Are there any API there to determine this.
thanks.
String value = android.provider.Settings.System.getString(context.getContentResolver(), android.provider.Settings.System.TIME_12_24);
Updated Answer, you should use this instead of the above, as above could give back a null value:
DateFormat.is24HourFormat(context)
This may help you....
The link of the answer source:
https://developer.android.com/reference/android/text/format/DateFormat.html#is24HourFormat(android.content.Context)

TimeFormatException while using time.parse()?

I'm trying to persistently store time data. I write the time to the preferences as a string passing it the time.toString(), and then restore it from the string by using the time.parse(String) method. However, I find that the parse method is throwing a TimeFormatException, specifically:
android.util.TimeFormatException: Unexpected character 0x41 at pos=15. Expected Z
I use logcat to view the string i am passing to parse, and it looks normal:
20110321T021030America/Detroit(1,79,-14400,1,1300687830)
Can anyone figure out why this is? Does the "expected Z" mean the letter Z specifically, or does it mean any integer, or what? And why is this happening? It seems like parsing a Time's toString() would be the easiest way to ensure that there ISN'T a timeformatexception, and yet I am still getting one.
It probably just doesn't recognise the format. You could use time.getTime() to get the unix time value instead, this might be easier to use.
The problem with parsing the date format which has been passed to time.parse(); function
Please refer the link to rectify you problem
Custom Date and Time Format Strings

Categories

Resources