Solved

Getting Time in Milis from International Date/Times

Posted on 2002-06-21
7
752 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

832 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