terajiv
asked on
Getting Time in Milis from International Date/Times
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
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
long l = new Date().getTime() will put the GMT milliseconds into l
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("Timezo ne offset in minutes is " + offsetZ);
int offsetDST = Calendar.DST_OFFSET;
System.out.println("Daylig ht 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));
}
}
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("Timezo
int offsetDST = Calendar.DST_OFFSET;
System.out.println("Daylig
int offset_ms = offsetZ + offsetDST * MS_CONV;
System.out.println("GMT (UTC) in milliseconds, allowing for offsets, is " + (t - offset_ms));
}
}
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 (DateForma t.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.
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
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>I want those with respect to GMT
Add Locale.UK at the getDateInstance method:
DateFormat df = DateFormat.getDateInstance (DateForma t.FULL, Locale.UK);
Add Locale.UK at the getDateInstance method:
DateFormat df = DateFormat.getDateInstance
Sorry about that - refreshed and reposted by accident. Also, have not read your question properly!
ASKER
The Problem is solved now... I appreciate Answer from CEHJ
Thanks all,
Raj
Thanks all,
Raj