SimpleDateFormat

Hello

I would like a similar functionality as the formatLocal method that does not take into account the time zone (just the time to format he I put in the constructor of output)

SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aaa");
String str1 = timeFormat.formatLocal(v.Start);

If I change the time zone in the settings (Options > Date/time), the date is not imptced in my application.

How to force the GMT format for example?

Thank you

MY

This thread help me?

How to get the current time in GMT?

http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=java_dev&message.ID=23879

Tags: BlackBerry Developers

Similar Questions

  • SimpleDateFormat giving different results for the same string in the form

    I use http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/i18n/SimpleDateFormat.html for formatting my date and time fields.

    I got a bug report that a device on English (UK) has a problem where the time turns off the screen, and I was able to reproduce this on device and Simulator.

    It's the pattern string that I use: hh:mma

    (hour 2 digits, colon, minute 2-digit and one letter for 'a' or 'p')

    English or r I get the result you want, for example 12: 12 p '

    "On English (UK), I get two letters for one / p marker, for example ' 12:12.

    (as if I had used 'hh:mmaa').

    What is the desired behavior? My client doesn't like it and wants a look and feel unique, with only one letter for 'a' or 'p', and I'm a little hesitatant to use aubstring...

    I usually do so, but our customer asked specifically localized to the date and time formatting.
    I have the model in my resource files, as the requested values are not easy to manage with the dateformat standard.

    Well, I have submitted comments on the entry of doc API, the doc is fake or the OS has a bug.
    I use substring if the string endsWith (am or pm) now...

  • SimpleDateFormat formatting question time

    SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");
    final DateField timeField = new DateField("", 0, timeFormat);
    

    Heres how I'm trying to format it, and then I'm filling timeField with my

    timerField.setDate (splitTime.getTimeMillis ());

    I'm triyng to indicate the time between my events, it all fine formats (minutes and seconds) but the string field formatting still displays the current hours our day and hour not between my events!

    It should always begin at 0 and then increase every hour. I don't want to show him the time of day, but my own timer time

    I find it weird that all other fields are working well, do not show the minute or second in the day, but the time field will not give.

    I use DateField to this effect.  Hours and minutes display correctly.

    What you have not thought, is that the DateField is specific time zone and by default, uses the local time zone.  So, if give you him a time of 1 hour, then it means actually 1 hour after midnight on time.  Now, the time is UTC, so this time will then be converted to what would be each 01:00 on January 1, 1970 in your time zone.  This is the problem that you are experiencing.

    To resolve this issue, it is simple, just set the time zone for the DateField to GMT.  And this should solve your problem.

    If you use this as an input field, you really be aware that she in fact display a date - just not showing the Date part.  So when you do a field getTime() you must extract just the hour and minute and ignore the game date.  For example, that you post at 18:00 because the user does something for 18 hours.  The user that comes to 01:00 and being sensitive, roll control up to 19, 20, 21, etc. 1.  Then the DateField will give back the next day (25 hours) not 1 hour.  Same thing happens if the user cancels the time.

    So the trick is to set the time zone on the DateField GMT and make sure you take any Date component if you use this entry.

    Hope this is clear.

  • HOW Timestamp()-> simpledateformat()?

    Hi community

    I am looking for best practices convert 'tim' (Java instructions below) in milli-seconds (since midnight 1970) human readable Date time &.

    I know pretty much on SimpleDateFormat() but don't know how to implement it.

    If anyone knows or can provide an example of code that will be great.

    ****

    Tim string = Long.toString (l.getTimestamp ()); timestamp

    ****

    Thanks in advance

    SimpleDateFormat needs an object for the entry, in this case, it would be a Date.
    l.getTimestamp () seems to offer a long, you can create a new Date for it.

    Here is an example of a formatted date complete with 24 h notation:

    SimpleDateFormat sdf = new SimpleDateFormat ("JJ. ("MM.yyyy, hh: mm");
    Tim of String = sdf.format (new Date (l.getTimestamp ()));

  • How to get to 01:00 using SimpleDateFormat?

    Hello

    I want to format 3 600 000 to 01:00, but always had a 06:00?

    What should I do to get in shape 3 600 000 at 01:00.

    my code:

    _formator = new SimpleDateFormat("HH:mm:ss");

    _formatedTime = (millisecond == 0)? 'Off': _formator.format (_countDate);

    I wonder still there is a better way, but now I have to do the following:

      private String formatTime(long microseconds)
        {
            String res = null;
            long seconds = microseconds/1000000;
    
            // get second digit
            long s = seconds % 60;
    
            // get minute digit
            long m = seconds/60 % 60;
    
            // get hour digit
            long h = seconds/3600 % 60;
    
            // add "0" before single digit number
            res = (h < 10 ? ("0" + h) : ("" + h))
                + ":" + (m < 10 ? ("0" + m) : ("" + m))
                + ":" + (s < 10 ? ("0" + s) : ("" + s));
    
            return res;
        }
    
  • SimpleDateFormat delta a day

    Hi all

    I do this:

    SimpleDateFormat format = new SimpleDateFormat("EEEE d MMMM");
    String dateStr = format.format(date);
    
    //First letter in major case "thanks" to SimpleDateFormat french error
    dateStr = dateStr.substring(0,1).toUpperCase() + dateStr.substring(1, day.length()) ;
    

    It works (almost) well.

    • With the 29 03 30/10. OK I get: «Monday 29 March' a string '2010-03-29'
    • Between 01/11 and 28/03 NOK, I get: "Saturday, March 27" for a string "" 2010-03-28.

    In conclusion it is a delta of a day less for a year from 01/11 to 28/03. I have never on 28 March and I get two 31 October.

    Have you had this problem before?

    I use the v4.6.0.303 9000 "BOLD", version french (as you might have guessed)

    It works fine on the curve 8529 4.6.1

    It seems that I really like the speech.

    Well for the people who live in * countries which change for hours during the year which may have the same problems, don't forget to add that:

    • If your date is at midnight (for example, 10-11-2010)
    • You must add 4 hours to be sure it convert for the good days

    Any Admin could check if this is a known issue?

  • The issue of the chain SimpleDateFormat

    What I'm missing here?

    SimpleDateFormat fmt = new SimpleDateFormat("h:mm a");
    String time = fmt.formatLocal(HttpDateParser.parse("2010-02-19 10:33:13"));
    

    Returns at 02:33

    my phone is in mode - 8 hours time Pacific...

    entry time is 24-hour format.

    What should I do to simply analyze the string and return it within my desired format? 12-hour format.

    10:33

    Do not know SimpleDataFormat, but SimpleDateFormat (Date, no data) is indeed in the Blackberry API...

    I think that your problem is time zones.  The date is to be treated as a UTC (GMT with no time) and then the local time format.

    TimeZone.getOffset can be added to it, and you can then use SimpleDateFormat.

    Alternatively you could just parse the string yourself.

  • SimpleDateFormat and safety wire

    I have a question regarding SimpleDateFormat and is the lack of thread safety.

    I have a DateUtils which a series of date-related operations, one of them being the analysis of the class in which the static method takes a string and analysis of a Date. I have a couple of SimpleDateFormats, and this method turns ' these and returns back a Date once a format is found. The problem I encounter is that these SimpleDateFormats are stored in a static table (because the method is static - it's in a util class, was to declare the array as static as well). With this configuration, is it not true that this poses a threat when several threads are run simultaneously? If so, can I use ThreadLocal to secure this thread? Or can I somehow remove the 'static' declaration and make it work?

    Thanks in advance.

    user1980584 wrote:
    I read on ThreadLocal and am a bit confused. What it does is basically give each thread is a local variable clean, correct? If this is the case, how is it different from simply creating an instance variable? It gives advantages of memory or performance?

    It depends on the instance in question. If an instance of the object is used by a single thread, then, Yes, by using an instance variable will work fine.

    ThreadLocal is useful for situations where:

    -you have 2 pieces of code that runs in the same thread that need to share data, but have no way to pass a reference directly a part of the code to the other (often due to limitations in the third-party vendor APIs)
    -you have a static class/method that is used by multiple threads and you need to store a State that is not shared between threads, but without requiring the appellant to maintain state

  • Formatting and parsing of text using SimpleDateFormat

    Here is a simple code:

    Date test1 = new Date();
    System.out.println (test1. ToString());

    SimpleDateFormat formatter = new SimpleDateFormat ("YYYY/MM/dd HH: mm :"); ")
    Date test2 = formatter.parse (formatter.format (test1));
    System.out.println (test2. ToString());

    If (test2.before (test1))
    {
    System.out.println ("test1 test2 is:" + test2.toString () + "," + test1.toString ());
    }

    And here is the result:
    Tue Sep 26 16:14:11 CEST 2010
    Tue Sep 26 16:14:11 CEST 2010
    is test2 before test1: Tue Oct 26 16:14:11 CEST 2010, Mar 26 Oct 16:14:11 CEST 2010

    Please can someone explain why test2 before test1?

    Thank you

    Hello

    When you format, whith seconds precision, the date of the ms are so lost before test1 test2

    System.out.println("Test 1 " + test1.getTime() );
    System.out.println("Test 2 " + test2.getTime() );
    

    Best reggards

    Published by: Séguy Gasques on October 26, 2010 08:17

  • Date format

    Hi guys,.

    I would like the blackberry datetime value in this format: YYYYMMDDHHMMSS

    I used this code:

    DateFormat df = new SimpleDateFormat ("yyyyMMddhhmmss");
    long dateLong = System.currentTimeMillis ();
    Date date = new Date (dateLong);
    String dateString = df.format (date);

    But what I get is 2009091651113 instead of 20090916051113

    or 2009091611113 instead of 20090916110113

    How to get the second format?

    Thank you

    My apologies, compilation problem was a cut and paste error!

    I retested and also saw the problem.  I don't see this is my code, I thought was similar, in fact uses HH hours rather than hh.  I tried the following, and it does not seem to remove 0 on what it is.

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd:HH:mm:ss");
    String dateString7 = sdf.format (date);
    String dateString8 = sdf.formatLocal (dateLong);

    I don't see the problem with "hh".  Is this correct?

    Sounds like something to report to the RIM!

  • Takeover online/offline

    Hello

    I am developing a small application that checks periodically if our server (tomcat) applications is online, but I don't get the results I expected. I'm pretty new to the connection API cannot do my implementation works.

    I create an object StreamConnection with Connector.open ("socket://ourappserver:8080 /;") deviceside = false"), but even when im disconnected from our local area network and the server is inaccessible I get the connection object and has no method I call to see if the server is online. Any suggestions would be greatly appreciated. I'll give you a little snippet of what I'm trying to do:

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");StreamConnection conn = null;conn = (StreamConnection) Connector.open(URL);if (conn != null) {        // Server online.  Date fecha = new Date(System.currentTimeMillis());    setEstado(df.format(fecha) + " " + "OK");   } else {        // Server down.   Date fecha = new Date(System.currentTimeMillis());    setEstado(df.format(fecha) + " " + "KO");}conn.close();
    

    After reading the API, the only thing I could think to solve this problem is when he throws an IOException message of KO. I need to hear what should I assess on the end line.

    if (conn != null) {
    

    The exception IOException is not thrown even if I unplug the network cable and make the application server unreachable. Thanks in advance,

    Francisco.

    The connection is not attempted until the RIM network code has something to send and/or knows you are waiting on it.  If you need to implement some sort of message type of heart rate if you want to use a socket connection.  As Tomcat is a Web server, and not a socket server, I recommend that you come to send a http request fast and have a static page on your Web server that responds always with something useful, like the time.

    Sorry, you are really going to have to communicate with your server to check if it is there.

  • Date in the form identical overall locale string

    Hi all

    I use a simple date format to convert the date to a string.

    It seems that for devices in some loacale returns the name of different Butterfly (not in English)

    I want each device in all locales must return string date in English (for example 1 March 2014)

    How to do this

    This constructor helps?

    SimpleDateFormat (String pattern, locale locale)

    Get the locale associated with LOCALE_en.

  • Problem of time setting Date DateField

    Hello.  I know I posted simillar in the past but now encounter the problem with what I think is linked to time zone.

    When I use the following code to set the time and date in a DateField leave a string I get the inconsitent results...

    DateFormat df = new SimpleDateFormat ("YYYY/MM/dd HH: mm");
    java.util.Calendar d2 = java.util.Calendar.getInstance (TimeZone.getDefault ());
    String date = ' 11/11/2011-14:11.
    yy int = 0, mm = 0, SD = 0, h = 0, e = 0;
    mm = Integer.parseInt (date.substring (0, 2)) - 1; January = 0
    DD = Integer.parseInt (date.substring (3, 5));
    YY = Integer.parseInt (date.substring (6, 10));
    HR = Integer.parseInt (date.substring (11,13));
    MI = Integer.parseInt (date.substring (14.16));
    D2. Set (Calendar.YEAR, AA);
    D2. Set (Calendar.MONTH, mm);
    D2. Set (Calendar.DATE, dd);
    D2. Set (Calendar.HOUR, human resources);
    D2. Set (Calendar.MINUTE, mi);
    D2. Set (Calendar.SECOND, 00);
    D2. Set (Calendar.MILLISECOND, 00);
    D2.setTimeZone (TimeZone.GetDefault ());
    long t2 = d2.getTime () .getTime ();
    _dateField = new DateField ("", t2, df);
    Add (_dateField);

    So will string ' 11/11/2011-14:11 ' to the datefield causes the time spend at 2010-11-12 02:11.  I've set the default calendar time zone doe.  Not sure why this is now occurring.

    Ah my bad, given the first bit and skips the rest! It is possible that you are using the TIME instead of HOUR_OF_DAY

  • How to display a given date in a DateField?

    Hi Experts,

    I'm developing an app for BlackBerry in Java. I want to display a date I will give statically for example "October 4, 2008. I did, but while reading, it is displayed in January 1, 1970. How can I display a static date in a DateField?

    Thank you and best regards,

    Nithya

    Simple use.

    import java.util.Date;

    Net.rim.device.api.i18n import. *;

    String date = new SimpleDateFormat("dd/MM/yyyy_hh:mm").format (new Date (System.currentTimeMillis ()));
    Add (new RichTextField (date));

  • How to set the default to 00:00:00 time in DateField

    I want to use the DateField to display a duration by default 00:00:00, but I'm still at the time as 12:00. Why?

    Calendar calendar = Calendar.GetInstance ();
    Calendar.Set (Calendar.HOUR_OF_DAY, 0);
    Calendar.Set(Calendar.minute,0);
    Calendar.Set(Calendar.second,0);
    SimpleDateFormat sdF = new SimpleDateFormat("hh:mm:ss");
    dateTime = new DateField ("", calendar.getTime () .getTime (), homeless);

    Use:

    SimpleDateFormat sdF = new SimpleDateFormat("HH:mm:ss");

Maybe you are looking for