Questions tagged [android-date]
276 questions
214
votes
31 answers
How can I get current date in Android?
I wrote the following code
Date d = new Date();
CharSequence s = DateFormat.format("MMMM d, yyyy ", d.getTime());
I want the current date in string format, like
28-Dec-2011
so that I can set it into a TextView.

Chatar Veer Suthar
- 15,541
- 26
- 90
- 154
208
votes
23 answers
Display the current time and date in an Android application
How do I display the current date and time in an Android application?

BIBEKRBARAL
- 4,455
- 9
- 31
- 30
127
votes
17 answers
how to convert milliseconds to date format in android?
I have milliseconds.
I need it to be converted to date format of
example:
23/10/2011
How to achieve it?

Pattabi Raman
- 5,814
- 10
- 39
- 60
51
votes
9 answers
Room Using Date field
I am using date converter class to convert my date object. However, I still encounter an error saying. error: Cannot figure out how to save this field into a database. You can consider adding a type converter for it.
My Date Converter class
public…

Sutirth
- 1,217
- 4
- 15
- 26
50
votes
10 answers
Convert time value to format “hh:mm Am/Pm” using Android
I am getting date value from database like "2013-02-27 06:06:30"
using StringTokenizer I will get time separately like below
String startTime = "2013-02-27 06:06:30";
StringTokenizer token = new StringTokenizer(startTime);
String date1 =…

Android learner
- 1,871
- 4
- 24
- 36
28
votes
10 answers
Compare Two String Date and Time in android?
I have Two String Datetime as follows:
String Date1 = "05-09-2013 10:46:10"
String Date2 = "06-09-2013 10:46:10"
I Need to compare these datetimes and i need result.

user2688507
- 281
- 1
- 3
- 3
25
votes
3 answers
How can I determine whether a device is using 12 or 24-hour time format?
I want to know the current device time format, meaning 24 hour/ 12 hour format.
Please let me know how can I determine that.
Are there any API there to determine this?

brig
- 3,721
- 12
- 43
- 61
24
votes
5 answers
Converting date-string to a different format
I have a string containing a date in the format YYYY-MM-DD.
How would you suggest I go about converting it to the format DD-MM-YYYY in the best possible way?
This is how I would do it naively:
import java.util.*;
public class test {
public…

lobner
- 593
- 1
- 7
- 15
22
votes
6 answers
How to format in Kotlin date in string or timestamp to my preferred format?
I'm getting date data from weather API in two versions. The first one is just string like this: 2019-08-07 09:00:00 and like this: 1565209665. How do I change it to just the name of the day or day and month?
For example Monday, August.
I tried…

beginner992
- 659
- 1
- 9
- 28
21
votes
11 answers
Get current time in a given timezone : android
I am new to Android and I am currently facing an issue to get current time given the timezone.
I get timezone in the format "GMT-7" i.e. string.
and I have the system time.
Is there a clean way to get the current time in the above given…

Vishesh Joshi
- 1,601
- 2
- 16
- 32
16
votes
4 answers
how to convert a date dd / mm / yyyy to yyyy-MM-dd HH:mm:ss Android
How can I convert a date in dd / mm / yyyy to a format that supports sqlite yyyy-MM-dd'T'HH: mm: ss
for example:
public static String convertStringToData(String stringData)
throws ParseException {
SimpleDateFormat sdf = new…

Douglas Mesquita
- 860
- 1
- 13
- 30
15
votes
5 answers
generate dates between two date in Android
How to get all dates between two dates in Android.
For example. I have two Strings.
String first="2012-07-15";
String second="2012-07-21";
I convert and get dates from these strings.
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd"); …

Hardik Joshi
- 9,477
- 12
- 61
- 113
13
votes
8 answers
how to get date from milliseconds in android
I have time in milliseconds, now I want to separate time and date from these milliseconds.
how can i do this???

Saqib Abbasi
- 607
- 2
- 6
- 17
12
votes
5 answers
How to handle time zone difference between server and native android application?
Suppose that my server located in USA and I live in Russia. We know that they have different time zones.
My application getting text(String) from server. And this text data has Date column in database to keep record date.
When I get data, I also get…

JustWork
- 1,944
- 3
- 22
- 34
11
votes
6 answers
Unknown pattern character 'x', when using SimpleDateFormat
Im trying to format a Date to String using SimpleDateFormat, and the pattern im using is this one
"yyyy-MM-dd'T'HH:mm:ss.SSSxxx"
but when reach this line
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSxxx");
i get the…

Thought
- 5,326
- 7
- 33
- 69