parsing date object with jodatime not working - android

When I try to parse Date object which has a format like 1950-01-01T00:00:00 then date time get it as yesterday.
i also tried to get time zone with DateTimeZone.getDefault() but its still not working.
Which timezone can I use to fix it?
DateTime dateTime = new DateTime(1950-01-01T00:00:00, DateTimeZone.UTC);
output:
dateTime.getDayOfMonth() = 31
dateTime.getMonthOfYear() = 12
dateTime.getYear() = 1949
Can you please help me?
Thanks.

fixed with adding below code in application class
DateTimeZone.setDefault(DateTimeZone.forID("Europe/Istanbul"));

Related

How to get android system date and time format in app

How can i get current time format that is set in android. Like it is 12 hrs or 24 hrs. I can easily get date and time and put format on it but i want to get current format of time from android system.
Use the following:
DateFormat.is24HourFormat(context);
Source: https://developer.android.com/reference/android/text/format/DateFormat.html#is24HourFormat(android.content.Context)
If you want to get a String you should use android.text.format.DateFormat
DateFormat dateFormat = android.text.format.DateFormat.getTimeFormat(context);
String = dateFormat.format(new Date());

SQLite Datetime Conversion?

I m developing android application. I need to convert datetime into date. I want to convert '25-07-2013 11:44AM' (datetime) into '25-07-2013' (date).
I am trying this function to convert SELECT date('25-07-2013 11:44AM'), but it was not working.Please suggest some solution for this problem.
According to this page, it does not seem that am/pm times are supported in date SQLite function (this should be noted as h or K according to the date format specification of Java at least; also it is explicitly mentioned %H hour: 00-24). Maybe experiment if using 24 hour clock will not trigger the issue.
I am not sure if you are search for Java code or SQL code , but if it is Java code then solution could be this :
String date = "25-07-2014 11:44AM";
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
String newDate = dateFormat.format(dateFormat.parse(date));
System.out.println(newDate);
If in case your are looking for SQL code let me know I will share that as well.

System.currentTimeMillis() in android?

i face problem with System.currentTimeMillis() in my project i write some code here where i got problem
Date currentDate = new Date(System.currentTimeMillis());
Log.v("1st",""+currentDate);
Date currentDate = new Date(System.currentTimeMillis()+25*24*60*60*1000);
Log.v("2nd","25th"+currentDate);
it displays current date see in first log but i add 25 days to current date it is in 2nd log but it is not working it displays 2 months back day. it is working very fine in between 1*24*60*60*1000 to 24*24*60*60*1000 days.after 24 it is not working please solve my problem
thanks in advance
25*24*60*60*1000>Integer.MAX_VALUE,
your should write as below:
new Date(System.currentTimeMillis()+25*24*60*60*1000l);
use Calendar instead
Calendar rightNow = Calendar.getInstance()
rightNow.add(Calendar.DAY_OF_YEAR, 25)
and the you can get the date object
You are mixing ints and longs. My java is a little rusty, but try:
Date currentDate = new Date(System.currentTimeMillis()+25L*24L*60L*60L*1000L);

How to add 15 days in String Date in android

I have a problem that I want to add 15 days in my date string but I don't know How to do that? Please help me regarding that.
Thanks in advance
You must parse the date by means of a DateFormat, then use a GregorianCalendar to do the maths:
Date date = DateFormat.getDateFormat(this).parse("12/31/1999");
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(date);
gc.add(Calendar.DAY_OF_MONTH, 15);
You can use the add method. Create a calendar object with the current date. And use the below method.
This should give you an idea
DateFormat objFormatter = new SimpleDateFormat("dd-MM-yyyy");
objCalendar.add(Calendar.DATE, 15);
return objFormatter.format(objCalendarDup.getTime());
Turn it into a java.util.Date and then use either java.util.Calendar or JODA time to do i
it.
A Date isn't a String. Use the types that are available to you. Convert the String into a Date using java.text.DateFormat.

How do I get the time in this format in android?

I am trying to get the present time in this format in an android app. time= "05:09pm 08/02/2011" Right now I am using Calendar c=Calendar.getInstance() and c.getTime() to get the time and its coming out as Tue Aug 23 02:34:25 PDT 2011.
Thanks
You need to use the DateFormat Class
Something like this will get you the current time in the format you desire.
DateFormat.format("hh:mmaa dd/MM/yyyy", System.currentTimeMillis());
Use a SimpleDateFormat.
Format should be like
SimpleDateFormat sdf = new SimpleDateFormat( "HH:mma dd/MM/yyyy" );
sdf.format( yourDate );
Regards,
Stéphane
There are many ways to do that in Android. You can use the SimpleDateFormat wich is a class for formatting and parsing dates. Formatting turns a Date into a String, and parsing turns a String into a Date. Or you can the class Formatter wich is low level but managing the localization is your responsibility.
You may find source code example on the Android javadoc on those classes

Categories

Resources