Solved

how to get yydddsssssmmmm format from Current Data base Timestamp in DB2

Posted on 2004-09-02
11
328 Views
Last Modified: 2008-01-09
Hi,

   My requirement is to generate unique sequence number with the following format

  i.e. yydddsssssmmmm

       yy = year
       ddd = julian date
       sssss = current seconds
       mmmm = milliseconds

I am able to do first 2 things. How about the rest.
I appreciate your ideas!!!

Thanks
0
Comment
Question by:mvkraju
11 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 11964461
what do you mean with "current seconds"? (and it can be 5 digits long????)
You don't mean the seconds part of the current time, do you?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11964516
and the same question for miliseconds ;-)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11964532
Guess you mean yydddssmmm.

Then you become the last part by

SimpleDateFormat fmt = new SimpleDateFormat("ssSSS");
String lastPart = fmt.format( new Date() );

0
 
LVL 37

Expert Comment

by:zzynx
ID: 11964541
...assuming you DO mean the (milli)seconds part of the current time
;°)
0
 

Author Comment

by:mvkraju
ID: 11964575
i mean
sssss - Seconds past midnight (0 - 86399).
mmmm - milli seconds past the second

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 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 11964645
>>sssss - Seconds past midnight (0 - 86399).
That's maths: sssss = hours * 3600 + minutes * 60 + seconds

>>mmmm - milli seconds past the second
Think you mean
      mmm - milli seconds past the second (0-999)

That's:
SimpleDateFormat fmt = new SimpleDateFormat("SSS");
String millis = fmt.format( new Date() );
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11964683

Calendar cal = Calendar.getInstance();
int hours = cal.get(Calendar.HOUR_OF_DAY);
int minutes = cal.get(Calendar.MINUTE);
int seconds = cal.get(Calendar.SECOND);
0
 

Author Comment

by:mvkraju
ID: 11965688
This is fine, how do i get Calendar from java.sql.Timestamp?
Because after i got DB Current Timestamp, i have it in java.sql.Timestamp object.
0
 

Author Comment

by:mvkraju
ID: 11965734
I mean without loosing nanos precision.
We can use set(int year, int month, int date, int hour, int minute, int second)  method of Calendar.
But i loose nono second precision.
0
 
LVL 21

Expert Comment

by:MogalManic
ID: 11965877
Try the following
  TimeStamp t;
  ...Get the data from DB...
  Calendar dt=Calandar.getInstance();
  dt.setDate(t);

  SimpleDateFormat fmt = new SimpleDateFormat("ssSSS");
  String lastPart = fmt.format(dt.getTime());
  lastPart=lastPart+t.getNanos();
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11970570
Thanks for accepting
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
mapAB Challlenge 35 126
Error with Java/Cache JDBC Classpath 2 31
JUnit 4 @Before and @BeforeClass differences 3 48
GUI builder for Eclipse? 8 27
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

911 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

16 Experts available now in Live!

Get 1:1 Help Now