Solved

Convert UTCTimestamp to java.util.Date

Posted on 2011-03-08
13
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

636 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