Date conversion madness! String to date and vice versa

Hello, I am working on an application targeting the OS version 4.5.x. I read a lot of messages and the links on this topic and can't seem to make the correct code.

OK, here's the problem. I ask a timestamp date string to a server. The timestamp is the local time on the server (IS / PST etc.) and not GMT.

My application must take time and subtract a number of days ranging from 1 day to 1 month. to get a "start" date The application must then provide the start and end date in a string format that it understands. Seems simple isn't?

Here's the catch, however the time stamps should NOT be changed by the local what is using the device. For example, a device in Italy can contact the server located in Ottawa and ask a timestamp, the calculations shouldn't care about DST or time zone. Just take the supplied date and subtract a fixed number of days from her. Nothing more or less. This proved incredibly hard to do. first the HttpDateParser.parse (ServerTimeStamp) will be the subject of Date GMT and my problem is back to the zone specified in ServerTimeStamp.

Thanks for any help in advance.

My method

public String getDAFIXMLRange (String ServerTimeStamp) {}
String szRange;
First analyze the incoming date and record them at the time of the last election.
Day DAFIEndDate = new Date (HttpDateParser.parse (ServerTimeStamp));
m_lLastPollTime = DAFIEndDate.getTime ();
        
define the offset. Pre-programmed for simplification.
lOffsetNumberOfSeconds long = 2 * 24 * 60 * 60;
        
      
Calculate the start date by subtracting the offset. Multiply by 1000 to convert to milliseconds!
Date DAFIStartDate = new Date (DAFIEndDate.getTime () - (lOffsetNumberOfSeconds * 1000));

!!!!!!!!!!!!! HOW the DATEFORMAT OBJECT is used to get the output format ' yyyy-MM-dd' you HH: mm: "without the marker of time zone. The server knows that it is local to it. !!!!!!!!!!

Now format the objects date as a string that includes the XML server.
DateFormat DafiDateFormat = DateFormat.getInstance (); ' YYYY-MM-dd' you HH.

!!!!!!!!!!!!!! THIS IS THE PART I'M CONFUSED on, with the HELP of zone to create the good date. !!!
Time zone tz = TimeZone.getTimeZone ("IS");
int adjEST = tz.getRawOffset ();

Convert 'em in string format.
String szDAFIStart = DafiDateFormat.format (DAFIStartDate);
String szDAFIEnd = DafiDateFormat.format (DAFIEndDate);

Replace the date calculated in the end segment ranges date XML.
szRange = statItems.replaceAll (XML_DATERANGE, "TAGSTARTTIME", szDAFIStart);
szRange = statItems.replaceAll (szRange, "TAGENDTIME", szDAFIEnd);
Return szRange;
}

Hello

Yes would be better if the server could provide you date to the GMT time zone, or date as a long.

But if you can't ask the case on the server, one way might be to manually parse your string and create a new date of parameter values in a calendar, something like this

Calendar cal = Calendar.GetInstance ();

Cal.Set (Calendar.DAY_OF_MONTH, date)

Cal.Set (Calendar.MONTH, month-1)

Cal.Set (Calendar.YEAR, year);

' set the new time with the values, you must cal.setTime (cal.getTime ()-,...);

and then put the date with SimpleDateFormat.

I think that this could be a solution if you know the format string you recived that date and it won't change.

I'm not sure but maybe it could be a solution.

Kind regards

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for

  • I can't put my keyboard clicking sound

    I have an iphone 16 G 5s with iOS 9.2.1 on that system. I always kept keyboard clicks and all of a sudden, they started clicking so I checked my settings, noticed that they were still closed, and I turn them on and turns off a few times only to find

  • Failed: Intel management engine Firmware Recovery Agent

    My new Y50 automatically runs a program called "Recovery Firmware Intel Management Agent" engine. This software checks the updates of drivers/firmware. HOWEVER on my machine updates verification FAILS. The error message is: 'we're sorry, but the upda

  • I start to download el captain, he paused now, how can I cancel

    I started to download el captain, he paused now, I have to cancel the download, memory goes to 99%, the system is very very slow, how can I cancel the download every 5 minutes I hv to restart the mac

  • Contacted by telephone by rep

    Contacted by "telephone identifying himself as Windows REP and I had more than 100 errors on my files. It was a random contact and said his name was "Vincent.  The statement coincided with the same "pop up" message that appears when ever I gwent in m

  • Clients vpn AnyConnect and cisco using the same certificate

    Can use the same certificate on the ASA client Anyconnect and cisco vpn ikev1-2?