Date and timezone using j2me - date

I have a date string as input from an rss like:
Wed, 23 Dec 2009 13:30:14 GMT
I want to fetch only the time-part, but it should be correct according to the my timezone. Ie, in Sweden the output should be:
14:30:14
What is the best way? I want it to work with other RSS date formats as well if possible. Im using regexp right now but that is not very general.
Im having a hard time finding any library or support for dates and timezones in j2me?
/Br Johannes

In normal Java, I'd use a SimpleDateFormat object (that you create to match the pattern of the date you're getting in the RSS) to parse the String value and give you a Date object. Then, using a Calendar (which would be localized to your time zone), you'd be able to get the hour, minute, and second information.
I don't know j2me, but a google search suggests that these classes are available in j2me.

Related

Keeping local Timezone information from an ISO 8601, RFC3339 formatted dates in iOS

I know there are tons of post regarding iso8601 strings and timezones but I could not find anything that really pinpoints the problem I had recently.
I have an ISO 8601 RFC3339 formatted string like: 2021-03-31T12:00:00+03:00.
I want to display the time associated with this date in the local time of the provided date meaning I want exactly "12:00" as the output. If my formatter has dateFormat of HH:mm
If I use an ISO8601DateFormatter to extract the date everything seems to work fine and the associated Date object is 2021-03-31 09:00:00 +0000. Which makes sense since 12:00GMT+3 = 09:00GMT+0
However this completely removes Timezone information from the Date object (which I know is by design on iOS).
While I understand the design behind this (most of the time we eventually should display the time in the user device timezone). There are quite a few exceptions like travel applications where we almost alway want to display the local time of departure/arrival.
My solution was to store the json serialized dates as Strings and use a combination of ISO8601DateFormatter to create the Date object in UTC and a normal DateFormatter that reconstructs the TZ from the +03:00 substring.
What's the best approach to solve this ?

Format date time in gwt with timezone

I am need to format a date and display it to users based on users location.
I am trying to format the time using the following code
DateTimeFormat.getFormat("h:mm a z").format(new Date(timeInMillis))
This is the result i am getting "5:18 PM UTC-4" for new york users and "2:18 PM UTC-7" for seattle users. How do i generate string like "5:18 PM EST" for new york users and "2:18 PM PDT" for seattle users?
Note: the problem with using format(new Date(time), timezone) is that how to create a timezone object based on user locale? Timezone.createTimeZone(int) gives SimpleTimeZone implementation which will produce "UTC-4", in-order to generate "PDT", timezone has to be created with Timezone.createTimeZone(timezoneJson: string) but issue in this is that we have to pick the timezone at the compile time to create the input timezone json string.
Thanks in advance
You need to pass a TimeZone object to the formatter:
format.format(new Date(), timeZone));
Note that the best way to create TimeZone is from a JSON string that contains information on changes to time zone in the past. If you app does not deal with time in the past, then this may not be necessary.

ApI blueprint Date format

I have problem understanding the following date formate from apiblueprint tutorial
2016-02-05T08:40:51.620Z
I now 2016 is the year 02 is the month 05 is the date and 08:40:51 is the time but I dont understand the last part .620Z.
Can some one explain it for me. I wanted to find out AM or PM of the time using javascript from the date using javascript and not sure whether the formate is 12 or 24 hours.
Thanks
First of all, API Blueprint doesn't require you to use any particular Date format; you are free to use whatever you want to.
The format used in the tutorial is the standard ISO 8601 format: .620 is the number of miliseconds, and Z designates a Zulu timezone, meaning UTC.

Format of docker remote api image date created field

Just wondering who might know what the number on the "created" attribute of the json response for images might mean.
Obviously its something to do with the day of creation, but I'm not sure how to format it, it doesnt look like a standard timestamp, does it represent "days ago" or a specific date?
How can I format this?
eg Created: 1402148149
As was stated by #Melbourne2991 that is a UNIX timestamp. Seconds since the epoch of Jan 1 1970. However, you will find that the Docker API is inconsistent about how it reports dates. /containers/json will give you the created field for all the returned containers as a UNIX timestamp, but /containers/DOCKERID/json will give you the same field in ISO 8601 format. Just something to consider when writing your code.

How to format timestamp in GWT app with given timezone?

I have to format date/time in my gwt app with specific timezone, which is loaded from the server. Possible timezones are like this GMT, GMT+1, GMT-2 etc...
Up to now i used DateTimeFormat to format my timestamps, and they used client's locale.
PLease help.
You can format in any timezone you want with DateTimeFormat, you just have to pass it as the second argument to the format method.
And to obtain a TimeZone object, depending on how you want to present the timezone information (if ever) in the formatted date/time, you can use either createTimeZone(int) or createTimeZone(String) (getting the string out of TimeZoneConstants).