Solved

Getting Time in Milis from International Date/Times

Posted on 2002-06-21
7
744 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
ID: 7098819
long l = new Date().getTime() will put the GMT milliseconds into l
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7098892
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
ID: 7099001
 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 7099014
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
ID: 7099017
>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
ID: 7099021
Sorry about that - refreshed and reposted by accident. Also, have not read your question properly!
0
 
LVL 3

Author Comment

by:terajiv
ID: 7104623
The Problem is solved now...  I appreciate Answer from CEHJ

Thanks all,

Raj
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
where is session ID cache stored 1 46
Java Jpanels and Jframe 8 28
servlet example issue 6 29
tomcat not starting 6 24
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

929 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

13 Experts available now in Live!

Get 1:1 Help Now