The Artima Developer Community
Sponsored Link

Java Answers Forum
Convert long date to byte array

1 reply on 1 page. Most recent reply: Nov 21, 2002 9:43 PM by Daniel Ray

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Lynn Hollerman

Posts: 67
Nickname: gmholler
Registered: Mar, 2002

Convert long date to byte array Posted: Nov 19, 2002 8:38 AM
Reply to this message Reply
Advertisement
I have a Java application that calls currentTimeMillis(), which according to the Java API returns a long. I need to convert this to an array of bytes. What is the best way to accomplish this? Most of the methods I'm thinking of would be for converting the long into a byte, and not a byte array. getBytes(), while it returns a byte array, works on a string, and I need to concatenate the raw bytes with another array of raw bytes, so I can't do that. Any ideas?

Thanks!

Lynn.


Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: Convert long date to byte array Posted: Nov 21, 2002 9:43 PM
Reply to this message Reply
Try this .. I haven't written code to test this.

long time = System.currentTimeMillis();

Long newTime = new Long(time);

String str = newTime.toString();

byte[] myByte = str.getBytes();


Ray

Flat View: This topic has 1 reply on 1 page
Topic: JAVA SOURCE FILE ANALYZER USING JTREE!!! Previous Topic   Next Topic Topic: JAVA

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use