Saturday, December 12, 2009

Stouffer's Outlet Solon

step Converting dates between time zones (2) Converting

In my previous post titled Converting dates between time zones
  • put an example of how to convert a date / time of a local time zone to a different. But working with the same project found that it should make a date in the UTC time zone to local, and then gave me my technical leader a simple solution changing one line of code example in the previous post, just to do what I needed at that time:
  • In the task you were doing was reading a text file with the data "date" as a series of numbers: "20090921" "1230", which represents the September 21, 2009 at 12:30, so I had to use the date format yyyyMMddkkmm. " This time he received the file represents a date / time in GMT time
    . And this time the area was to go to my local time is CST or UTC-6 (Central Time) . Public void
    cambiarZonaHoraria (String date, String pattern, String tz) { SimpleDateFormat format = new SimpleDateFormat (pattern);
    format.setTimeZone (TimeZone.getTimeZone (tz)); try {System.out.println (format.parse (date));
    } catch (ParseException pe) {pe
    . printStackTrace ();
    }} first creates a new instance of SimpleDateFormat with the parameter "pattern" that tells the body that the text is going to shipping is in this format, in my case "yyyyMMddkkmm."
    Then, most important of what we try do, we will assign our object the TimeZone
    format in which you want to convert the time, in my case was GMT. then simply use the method parse (String)
    to convert our text to a Date in the local timezone, in my case CST, so the end result of this example is that the text "200909211230" in format yyyyMMddkkmm "which represents" 2oo9/09/21
    12:30
     "GMT becomes" 2009/09/21 6:30 

    "in CST and which is 6 hours behind the benchmark of
    Time UTC Coordinated Universal or
    .

    only exceptions must remember catching a throw or make them.


    0 comments:

    Post a Comment