Solved

Getting Time in Milis from International Date/Times

Posted on 2002-06-21
7
764 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 83
ejb on wildfly 5 61
Java program running SQL query 5 59
Need Help! Getting a syntax error and don't understand why 3 53
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…
Suggested Courses

738 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