Join Date and Time to DateTime in C#

后端 未结 8 819
孤城傲影
孤城傲影 2020-12-25 09:46

I am retrieving data from an iSeries where there is a separate date and time fields. I want to join them into a DateTime field in my C# project. I don\'t see a way to add ju

相关标签:
8条回答
  • 2020-12-25 10:21

    You can add a TimeSpan to a DateTime and write something like this.

    // inside consuming function
    ISeriesObject obj = getMyObject();
    DateTime dt = getDate(obj) + getTime(obj);
    
    private DateTime getDate(ISeriesObject obj)
    {
         //return a DateTime
    }
    
    
    private TimeSpan getTime(ISeriesObject obj)
    {
         //return a TimeSpan
    }
    
    0 讨论(0)
  • 2020-12-25 10:21

    Cant you simply format the date part and time part as separate strings, then join them together? Then you can parse the string back to a DateTime object

    0 讨论(0)
提交回复
热议问题