Solved

Convert UTCTimestamp to java.util.Date

Posted on 2011-03-08
13
321 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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.

707 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

12 Experts available now in Live!

Get 1:1 Help Now