[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3057
  • Last Modified:

toGMTstring Deprecated to ???

Hi all,

   In an applet, I was using this toGMTstring method, but for some reasons I needed to re-compile this applet, but this time with this new jdk1.3 and it gives all the errrors in the world to me.
   So the problem is :

   How to get the GMT time for the local Time ?

0
clique10
Asked:
clique10
1 Solution
 
dmaguilloCommented:
Hi clique 10.

U must replace it by:

DateFormat.format(Date date)

Bye... :)
0
 
Jim CakalicSenior Developer/ArchitectCommented:
Specifically, if you currently have:

    import java.util.Date;
    ...
    Date date = new Date();
    String gmt = date.toGMTstring();

replace it with the following:

    import java.util.Date;
    import java.util.TimeZone;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    ...
    Date date = new Date();
    DateFormat df = new SimpleDateFormat("dd MMM yyyy kk:mm:ss z");
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    String gmt = df.format(date);

The String result in gmt will be _exactly_ the same as that previously generated by the Date.toGMTstring method.

Date still represents a specific instant in time, with millisecond precision. Prior to JDK 1.1, the class allowed the interpretation of dates as year, month, day, hour, minute, and second values, and the formatting and parsing of date strings. Unfortunately, the API for these functions was not amenable to internationalization. As of JDK 1.1, the Calendar class should be used to convert between dates and time fields and the DateFormat class should be used to format and parse date strings. The corresponding methods in Date are deprecated.

Best regards,
Jim Cakalic
0
 
clique10Author Commented:
Thanks Jim !!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now