Solved

Convert UTCTimestamp to java.util.Date

Posted on 2011-03-08
13
323 Views
Last Modified: 2012-05-11
Just small question, how to convert Date from UTCTimestamp to java.util.Date?
Thank you
0
Comment
Question by:gbcbr
  • 6
  • 5
  • 2
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35070228
Date d = new Date(longValue) would do it, but what form is this timestamp in? What type?
0
 

Author Comment

by:gbcbr
ID: 35070294
I have original array Data in UTC format:
if (message instanceof MarketDataSnapshot) {

            incomingQuote = (MarketDataSnapshot)message;
            symbol = incomingQuote.getInstrument().getSymbol();
            double bPx = incomingQuote.getBidOpen();
            double aPx = incomingQuote.getAskOpen();
            UTCTimestamp ts = incomingQuote.getOpenTimestamp();

            try {

                if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    
                    BorderControl.getInstance().borderControl(bidPx,
                                                              askPx);
                    bidPx[0] = bPx;
                    eurusd_bid = String.valueOf(bidPx[0]);
                    DCC.getInstance().setEURUSD_bid(eurusd_bid);
                    askPx[0] = aPx;
                    eurusd_ask = String.valueOf(askPx[0]);
                    DCC.getInstance().setEURUSD_ask(eurusd_ask);
                    avg[0] = (bidPx[0] + askPx[0])/2;
                    avg_ts[0] = ts;
                    ChartCommander.getInstance().chartEURUSD(avg, avg_ts, outY);
                }

Open in new window

I need to send it to OHLC, but there java.util.Date format and I have error message:
Cannot cast UTCTimestamp[] to java.util.Date[].
So, before sending I have to convert it to acceptable format.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35070362
UTCTimestamp is in what API?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:gbcbr
ID: 35070374
import com.fxcm.fix.UTCTimestamp;
0
 

Author Comment

by:gbcbr
ID: 35070406
I can't send .jar file
The extension of the uploaded file is not in the list of accepted extensions.
How to send it?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 35070416
Undocumented for me, so try something like

Date d = new Date(ts.getTime());
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35070440
>>How to send it?

You can't to this site - they ban the contents as well as the archive extensions. Try mailing it to me (see profile)
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 35070584
Use
Date d = ts.toDate();

Open in new window

0
 

Author Comment

by:gbcbr
ID: 35070618
Thank you it works , even Date d = new Date(ts.getTime()); works
0
 
LVL 92

Expert Comment

by:objects
ID: 35074029
you probable don't need to convert them at all, you can probably just copy them into new array. Simpler, and avoids wasting memory.
you only need to convert when going the other way, converting a date to a timestamp
0
 

Author Comment

by:gbcbr
ID: 35074080
Unfortunately when you work, I'm sleep and vise versa
0
 
LVL 92

Expert Comment

by:objects
ID: 35074907
I have lots of student, clients and developers in different timezones.  Its a challenge, but we manage to make it work. just need to get in sync :)
0
 

Author Comment

by:gbcbr
ID: 35074940
I agree, to solve my questions I've change my standard timetable, normally I have to sleep now, but I'm still alive!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

785 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