|
|
||||||
|
#1
|
|
|
|
|
Ive search this newsgroup and google for a couple days now(off and on)
and have not been able to figure this out. How do I get the current system time in the format: 2005-03-02T16:40:37.46Z ? I beleive people call this Zulu time, or military time? I have a way of "kludging" it together by pulling out each field of a Calendar instance but I think there's got to be a better way. Thanks in advance, Kevin |
|
|
|
#2
|
|
|
|
|
On 19 Aug 2005 15:41:53 -0700, netkev wrote or quoted :
>I beleive people call this Zulu time, or military time? I have a way >of "kludging" it together by pulling out each field of a Calendar >instance but I think there's got to be a better way. to get anything like that you would need a SimpleDateFormat. See http://mindprod.com/jgloss/calendar.html |
|
#3
|
|
|
|
|
On 19 Aug 2005 16:04:12 -0700, "ninhoa" <ninhoa> wrote or
quoted : >> system time in the format: 2005-03-02T16:40:37.46Z ? > >Something like this? (copied from the SimpleDateFormat javadocs) > >SimpleDateFormat sdf = new >SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"); >System.out.println(sdf.format(new Date())); SSS would give milliseconds. What does SS give? centiseconds or an overflowing ms field? |
|
#4
|
|
|
|
|
On 19 Aug 2005 16:04:12 -0700, "ninhoa" <ninhoa> wrote or
quoted : > >SimpleDateFormat sdf = new >SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"); >System.out.println(sdf.format(new Date())); That's not quite right. That will give you local time. I think he wants UTC. |
|
#5
|
|
|
|
|
On 19 Aug 2005 15:41:53 -0700, netkev wrote or quoted :
> How do I get the current >system time in the format: 2005-03-02T16:40:37.46Z ? this code is posted at http://mindprod.com/jgloss/calendar.html import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Zulu { /** * Display current Zulu/UTC military time, * e.g. 2005-08-21T03:28:48.09Z * @param args not used */ public static void main ( String[] args ) { SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ); TimeZone utc = TimeZone.getTimeZone( "UTC" ); sdf.setTimeZone ( utc ); String milliformat = sdf.format( new Date() ); // convert from milliseconds to centiseconds // by chopping off last digit String zulu = milliformat.substring( 0, 22 ) + 'Z' ; System.out.println( zulu ); } } |
|
#6
|
|
|
|
|
On Sun, 21 Aug 2005 03:15:16 GMT, Roedy Green
<look-on> wrote or quoted : >>SimpleDateFormat sdf = new >>SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'"); >>System.out.println(sdf.format(new Date())); > >SSS would give milliseconds. What does SS give? centiseconds or an >overflowing ms field? Actually it gives the same as SSS, a three digit field. |
|
|
| Similar Threads | |
| why java timestamp format is different form php or normal unix format i'm wrting an application both in php and java i notice that java unixstamp is differenet from php any one know why ? java format 1203862011828 php and unix... |
|
| java.sql.Timestamp and toString output according to [..]), Returns: a String object in yyyy-mm-dd hh:mm:ss.fffffffff format however, when I do import java.sql.Timestamp; ... Timestamp ts = new Timestamp(1000); |
|
| GIISR.DLL timestamp of module does not match timestamp of local mo Hello there, when debugging my ARM-based image, I get the warning: Loaded '{myDir}\GIISR.DLL', timestamp of module on device does not match timestamp of local module. I... |
|
| Java Timestamp in SQL // DO NOT DO THIS! // BUG: loses time of day preparedStatement.setDate(1, new java.sql.Date(date.getTime())); // DO THIS preparedStatement.setTimestamp(1,... |
|
| Convert unix timestamp to postgres timestamp I'm writting a little calendar script and I need to insert a pair of start and end timestamps into a postgres database table. These are in unix format (seconds since 1st Jan... |
|
|
All times are GMT. The time now is 01:31 PM. | Privacy Policy
|