Results 1 to 14 of 14

Thread: Date formatting

  1. #1
    bikkerss is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default Date formatting

    Hi i have the next problem i save a form with dates to a sqllite database
    the dates are viewed by the users as "07 mei 2010" (dutch format) but i need to save it as an american format "2010-05-07" otherwise search functions on date in sql lite don't work wel

    exp: "select date from questions where date between '1 mei 2010' and '7 mei 2010'

    gives the complete database.

    between 2 mei 2010 and '7 mei 2010' works as it should.

    with american formatting this problem is solved but how can i convert the american formatting back to dutch ?

    i use netbeans with formattedtextfields

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Are you able to set your Locale to Dutch? If so, then SimpleDateFormat should work for you as it would then be able to translate a Dutch date to other formats easily.

  3. #3
    bikkerss is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default

    That's the problem there's no Dutch in the locale list
    so i don't know how to solve this (just a beginner)

    if i look here http://java.sun.com/j2se/1.4.2/docs/...ocale.doc.html Dutch is provided but i don't see it in Netbeans
    Can this help me with my problem ?

    Quote Originally Posted by Fubarable View Post
    Are you able to set your Locale to Dutch? If so, then SimpleDateFormat should work for you as it would then be able to translate a Dutch date to other formats easily.
    Last edited by bikkerss; 05-08-2010 at 02:36 PM.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by bikkerss View Post
    That's the problem there's no Dutch in the locale list
    so i don't know how to solve this (just a beginner)
    Sorry, I don't know, but don't give up hope as there are smarter folks, many from the Netherlands, who check this forum regularly.

    Much luck!

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bikkerss View Post
    with american formatting this problem is solved but how can i convert the american formatting back to dutch ?
    The Locale("nl") is fully supported.

    kind regards,

    Jos

  6. #6
    bikkerss is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default

    how do i need to use this if i juse locale in netbeans i only seen canada till us but no dutch

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    What do you see if you run this?

    Java Code:
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Locale;
    
    public class DutchDate {
      public static void main(String[] args) {
        Calendar today = Calendar.getInstance();
        System.out.println(today.getTime());
        
        Locale dutchLoc = new Locale("nl");
        SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM dd, yyyy", dutchLoc);
        System.out.println(sdf.format(today.getTime()));
        
      }
    }

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by bikkerss View Post
    how do i need to use this if i juse locale in netbeans i only seen canada till us but no dutch
    Do you see the "nl" locale if you run this code snippet?

    Java Code:
    import java.util.Locale;
    
    public class LLL {
    	public static void main(String[] args) {
    
    		Locale[] ls= Locale.getAvailableLocales();
    		
    		for (Locale l : ls)
    			System.out.println(l);
    	}
    }
    kind regards,

    Jos

  9. #9
    bikkerss is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default

    output:

    Sat May 08 16:20:00 CEST 2010
    zaterdag, mei 08, 2010

    Quote Originally Posted by Fubarable View Post
    What do you see if you run this?

    Java Code:
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Locale;
    
    public class DutchDate {
      public static void main(String[] args) {
        Calendar today = Calendar.getInstance();
        System.out.println(today.getTime());
        
        Locale dutchLoc = new Locale("nl");
        SimpleDateFormat sdf = new SimpleDateFormat("EEEE, MMMM dd, yyyy", dutchLoc);
        System.out.println(sdf.format(today.getTime()));
        
      }
    }

  10. #10
    bikkerss is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default

    are these al the options i can use instade of the "nl" option ?

    output:

    ja_JP
    es_PE
    en
    ja_JP_JP
    es_PA
    sr_BA
    mk
    es_GT
    ar_AE
    no_NO
    sq_AL
    bg
    ar_IQ
    ar_YE
    hu
    pt_PT
    el_CY
    ar_QA
    mk_MK
    sv
    de_CH
    en_US
    fi_FI
    is
    cs
    en_MT
    sl_SI
    sk_SK
    it
    tr_TR
    zh
    th
    ar_SA
    no
    en_GB
    sr_CS
    lt
    ro
    en_NZ
    no_NO_NY
    lt_LT
    es_NI
    nl
    ga_IE
    fr_BE
    es_ES
    ar_LB
    ko
    fr_CA
    et_EE
    ar_KW
    sr_RS
    es_US
    es_MX
    ar_SD
    in_ID
    ru
    lv
    es_UY
    lv_LV
    iw
    pt_BR
    ar_SY
    hr
    et
    es_DO
    fr_CH
    hi_IN
    es_VE
    ar_BH
    en_PH
    ar_TN
    fi
    de_AT
    es
    nl_NL
    es_EC
    zh_TW
    ar_JO
    be
    is_IS
    es_CO
    es_CR
    es_CL
    ar_EG
    en_ZA
    th_TH
    el_GR
    it_IT
    ca
    hu_HU
    fr
    en_IE
    uk_UA
    pl_PL
    fr_LU
    nl_BE
    en_IN
    ca_ES
    ar_MA
    es_BO
    en_AU
    sr
    zh_SG
    pt
    uk
    es_SV
    ru_RU
    ko_KR
    vi
    ar_DZ
    vi_VN
    sr_ME
    sq
    ar_LY
    ar
    zh_CN
    be_BY
    zh_HK
    ja
    iw_IL
    bg_BG
    in
    mt_MT
    es_PY
    sl
    fr_FR
    cs_CZ
    it_CH
    ro_RO
    es_PR
    en_CA
    de_DE
    ga
    de_LU
    de
    es_AR
    sk
    ms_MY
    hr_HR
    en_SG
    da
    mt
    pl
    ar_OM
    tr
    th_TH_TH
    el
    ms
    sv_SE
    da_DK
    es_HN


    Quote Originally Posted by JosAH View Post
    Do you see the "nl" locale if you run this code snippet?

    Java Code:
    import java.util.Locale;
    
    public class LLL {
    	public static void main(String[] args) {
    
    		Locale[] ls= Locale.getAvailableLocales();
    		
    		for (Locale l : ls)
    			System.out.println(l);
    	}
    }
    kind regards,

    Jos

  11. #11
    bikkerss is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default

    thanks i think i got it

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You are getting nl_NL, so you're good.

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    You are getting nl_NL, so you're good.
    The "NL" part is a country code, there's also an "nl_BE" locale; it represents the flemisch language.

    kind regards,

    Jos

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    My latest take on this:
    Java Code:
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    
    public class DutchDate {
      public static void main(String[] args) throws ParseException {
        String[] dutchDates = {
            "2 mei 2010",
            "7 mei 2010"
        };
        
        Locale dutchLoc = new Locale("nl", "NL");
        
        String nlFormatStr = "dd MMMM yyyy";
        String usFormatStr = "yyyy-MM-dd";
        
        SimpleDateFormat nlSdf = new SimpleDateFormat(nlFormatStr, dutchLoc);
        SimpleDateFormat usSdf = new SimpleDateFormat(usFormatStr, Locale.US);
        
        for (int i = 0; i < dutchDates.length; i++) {
          System.out.println("NL Date: " + dutchDates[i]);
          Date date = nlSdf.parse(dutchDates[i]);
          System.out.println("US Date: " + usSdf.format(date));
        }
        
        
      }
    }

Similar Threads

  1. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  2. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM
  3. Formatting time and date
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 07:35 PM
  4. Difference between current date and anothe date
    By vijay balusamy in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 04:15 PM
  5. Formatting the date
    By yuchuang in forum New To Java
    Replies: 5
    Last Post: 05-07-2007, 06:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •