Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How to format Date object in Android similar like Gmail displays it
1. If the date is <24h from now, print hour ie 12:12am
2. If the date >24h but <1 week, print day name, ie Wednesday
3. If the date > 1 week, print date ie 2013-08-12
Thanks
Here's a good place to get started:
DateUtils.getRelativeTimeSpanString (long time, long now, long minResolution)
Parameters
time is the time to describe, in milliseconds.
now is the current time in milliseconds.
minResolution is the minimum timespan to report.
For example, a time 3 seconds in the past will be reported as "0 minutes ago" if this is set to MINUTE_IN_MILLIS. Pass one of 0, MINUTE_IN_MILLIS, HOUR_IN_MILLIS, DAY_IN_MILLIS, WEEK_IN_MILLIS
http://developer.android.com/reference/android/text/format/DateUtils.html#getRelativeTimeSpanString(long,%20long,%20long)
Related
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 4 years ago.
Improve this question
Pardon me if it's not the right place to post, but I'm so curious about this.
So December 5th is a date. Last year it fell on a Tuesday.
How can modulo be used to work this out?
I know this is a modulo problem, but just don't get how modulo is used here.
A famous algorithm for calculating the day of the week based on the date is Zeller's algorithm. If you follow that link to wikipedia, you will see the algorithm, which uses the modulus operator.
It is used to calculate the year of the century (denoted K) by doing
current year % 100
It's also used at the end of the expression, where we calculate modulo 7 of the formula shown on wikipedia:
https://wikimedia.org/api/rest_v1/media/math/render/svg/0f95195dcc0d98b351294277071736e97053324e
With a little intuition, you will realize 7 is used because there are 7 days in the week.
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 6 years ago.
Improve this question
So, my first app will be a personal one to help me meet deadlines. As you would imagine it is going to be very date oriented.
So, how do I grab the current date from my phone/emulator?
Bonus points if you can explain how to put it into an integer.
Any link or tutorial would be super great.
Thanks in advance.
You can get the time of your phone by creating a calender.
Calendar calendar = Calendar.getInstance();
This stores your actual time. If you want to get the date in a number, just us this:
long timeInANumber = calendar.getTimeInMillis();
You need to use a long instead of a integer, because this number is so big. A long is like a integer, but it can store greater values.
The number you get (called UNIX Timestamp) represents the count of milliseconds since 00:00 Janurary 1st, 1970.
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 7 years ago.
Improve this question
I have a java program which makes a JNI call. From java, I am sending Date.getTime() (basically seconds * 1000), and I expect C++ to convert it to a perfect date.
NOT DUPLICATE: I KNOW MANY SOLUTIONS EXIST ON STACKOVERFLOW, BUT NONE OF THEM SEEM TO WORK WITH DATES SINCE 01-01-0001
I need the dates to get perfectly generated, for as early as 01-01-0001 00:00:00.
Any clue or code snippet in C++?
This assumes that getTime() works according to the java docs outputting time since 1970.
Try this:
How can I convert seconds since the epoch to hours/minutes/seconds in Java?
(Edit: even though the question is for Java the implementation given in the first answer is in C, which is (mostly) valid C++ code. It doesn't account for leap seconds so just subtract the number of leap seconds since 1970 before evaluating)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
How many digits System.nanoTime() produce. Whether these digits are fixed or can vary in count?
Thanks
System.nanotime returns a high-resolution clock value from your system. It does not have any kind of defined interpretation other than that if you take the difference between the return value from two separate calls to System.nanotime, you will get an approximate number of nanoseconds that elapsed between those calls.
So the number of digits is not fixed, because there is no specific format for System.nanotime's value, and there is no meaningful way to interpret it. Only use the difference between two calls to System.nanotime.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my JSON response i am getting date like this [1987,8,22], but I have to display the date like 22-08-1987. Can anyone tell me how to convert this.
Thanks in advance.
Use the org.json package to parse the JSON into a JSONArray (if your haven't already done so). Then you can instantiate a GregorianCalendar using the three elements of the array accessible through JSONArray.getInt. This date then can be formatted as any other Java date object.
You can try this::
String date = "1987,8,22";
String[] part = date.split(",");
date = part[2]+"-"+part[1]+"-"+part[0];
Hope it Helps!!