0

I have input date which is in set in ZoneDateTime format, and it is converted to Date Time format. Now I need to set the value from database which is date that has time too (Timestamp). How to set the out?

inputs:

private ZonedDateTime StrtDate;         
public void ZonedDateTime getStrtDate(){      
    return StrtDateGmt             
}     

public void ZonedDateTime setStrtDate(ZonedDateTime StrtDateGmt){     
    this.StrtDate=StrtDate;
}

conversion:

public static String formatDateString(ZonedDateTime date){     
    String result="";           
    if(date!=null){         
        DateTimeFormatter fmt=DateTimeFormatter.ofPattern(DATE_FORMAT);            
        res=date.format(fmt);
        if(date.getOffset()!=null){
            result+="";
            result+=Integer.toString(date.getOffset().getTotalSeconds()/3600;}}
            result result;
        }

        // setting/mapping the output from db:
        // i have written in this way
        dBtable.setstrtDate((ZonedDateTime)response.get(P_Strt_Dt);

How to set the output from datebase which has date in timestamp format

I was getting exception: date cannot be cast to ZonedDateTime. I don't know whether it is correct or not. How to set the output?

Ole V.V.
  • 65,573
  • 11
  • 96
  • 117
simmy
  • 1
  • 1
  • If I understand correctly a possible duplicate of [Java8 java.util.Date conversion to java.time.ZonedDateTime](https://stackoverflow.com/questions/25376242/java8-java-util-date-conversion-to-java-time-zoneddatetime). Have a look. And search for more. Or depending on how you look at it possible duplicate of [java.lang.ClassException: A cannot be cast into B](https://stackoverflow.com/questions/17217965/java-lang-classexception-a-cannot-be-cast-into-b). – Ole V.V. Feb 13 '19 at 03:14
  • Welcome to Stack Overflow. It’s better if you can post code that doesn’t have other errors than the error you are asking about, so we can try and see for ourselves. Best complete code, but not too much. See [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Ole V.V. Feb 13 '19 at 03:26
  • You cannot just cast a date or timestamp object into a ZonedDateTime, you're going to actually need to create a ZonedDateTime variable based on the Date or Timestamp. For this you also need a timezone (ZoneId). – Sebastiaan van den Broek Mar 22 '19 at 18:41

0 Answers0