Solved

Getting Time in Milis from International Date/Times

Posted on 2002-06-21
7
731 Views
Last Modified: 2007-12-19
Hello All,

I want to Convert all the incoming Date/Time String into Miliseconds.

e.g. I may get Following dates in String Format
 1. 08 May 2002 08:24:37 GMT+10:00
 2. 13 Jun 2002 23:58:06 EST
 3. 24 Apr 2002 13:12:31 PDT
 4. Sat Mar 30 00:23:53 GMT+02:00 2002
 5. 02 Apr 2002 15:59:26 CST

I want a generalized Solution for getting Above Dates into GMT Specific Miliseconds... I want those with respect to GMT and not EST, PDT or CST etc.

Help me out of this please...

Raj
0
Comment
Question by:terajiv
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
long l = new Date().getTime() will put the GMT milliseconds into l
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
According to the docs, it would seem the situation is more like:

import java.util.*;

class DateOffs {
      static int MS_CONV = 60 * 1000;
     
      public static void main(String[] args) {
           Date d = new Date();
           long t = d.getTime();
           System.out.println("GMT (UTC) in milliseconds is " + t);
           int offsetZ =  Calendar.ZONE_OFFSET;
           System.out.println("Timezone offset in minutes is " + offsetZ);
           int offsetDST = Calendar.DST_OFFSET;
           System.out.println("Daylight Saving Time  offset in minutes is " + offsetDST);
           int offset_ms = offsetZ + offsetDST * MS_CONV;
           System.out.println("GMT (UTC) in milliseconds, allowing for offsets, is " + (t - offset_ms));  
      }
 }
 
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
 The following should work for the four of them:

String s = "08 May 2002 08:24:37 GMT+10:00";
String s2 = "13 Jun 2002 23:58:06 EST";
String s3 = "24 Apr 2002 13:12:31 PDT";
//String s4 = "Sat Mar 30 00:23:53 GMT+02:00 2002";
String s5 = "02 Apr 2002 15:59:26 CST";
DateFormat df = DateFormat.getDateInstance(DateFormat.FULL);
Date d = df.parse(s5); // change the s5 for every Sting variable
long l = d.getTime();
System.out.println("l: " + l);

  As for the s4 string I have never seen this date format before.

  Hope it helps.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
Comment Utility
According to the docs, it would seem the situation is more like:

import java.util.*;

class DateOffs {
      static int MS_CONV = 60 * 1000;
     
      public static void main(String[] args) {
           Date d = new Date();
           long t = d.getTime();
           System.out.println("GMT (UTC) in milliseconds is " + t);
           int offsetZ =  Calendar.ZONE_OFFSET;
           System.out.println("Timezone offset in minutes is " + offsetZ);
           int offsetDST = Calendar.DST_OFFSET;
           System.out.println("Daylight Saving Time  offset in minutes is " + offsetDST);
           int offset_ms = offsetZ + offsetDST * MS_CONV;
           System.out.println("GMT (UTC) in milliseconds, allowing for offsets, is " + (t - offset_ms));  
      }
 }
 
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
>I want those with respect to GMT

  Add Locale.UK at the getDateInstance method:

DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.UK);
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Sorry about that - refreshed and reposted by accident. Also, have not read your question properly!
0
 
LVL 3

Author Comment

by:terajiv
Comment Utility
The Problem is solved now...  I appreciate Answer from CEHJ

Thanks all,

Raj
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now