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
I need help with formatting date in Android. I have learned how to implement date like this yyyy-MM-dd but now I want like this Dec 31, 1969. How can I implement this dateFormat in Java?
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy");
System.out.println(sdf.format(new Date()));
It will return the Date at your requested format!
Are you looking for something like this?
http://developer.android.com/reference/java/text/DateFormat.html
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 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 string which means a date. it looks like this :
/Date(1448880305230+0200)/
So how to convert it to Calendar or any type of date ?
The string above in your question doesn't look like unixtime, but technically speaking you can use SimlpeDateFormat to format your date like this:
long unixSeconds = 1372339860;
// *1000 is to convert seconds to milliseconds
Date date = new Date(unixSeconds*1000L);
// the format of your date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
String formattedDate = sdf.format(date);
//Log it in
//System.out.println(formattedDate);
//Log.d(formattedDate);
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 8 years ago.
Improve this question
I'm developing an android application.
This time format returns to me as a string from the database -->"PT20H" and I want to convert it to the following format --> "20:00".
Any ideas??
Thanks in advance.
What you want to do is called parsing a time string. Take a look at SimpleDateFormat
Its seems like you've got some plain text that isn't informative, being the PT and the H. That is, if all your times are whole hours only (eg "PT20H23M" for 20:23 does not occur. I believe the pattern to use should be "'PT'H'H'"
That is PT (between quotes to signify text to ignore, then the hour (symbol H) and then H between quotes again because it is to be ignored.
SimpleDateFormat sdf = new SimpleDateFormat("'PT'H'H'");
Date theDate = sdf.parse("PT20H");
SimpleDateFormat newFormat = new SimpleDateFormat("H:m");
String newFormattedString = newFormat.format(theDate);