0

I'm going by this tutorial and trying to figure out how to have a DataMember without an auto property. Basically I have a field is a date time in epoch format and I want the property to be a DateTime so I'm trying to do the conversion in the property's get. I'm not sure how to format this exactly.

Since Code was requested please look at the following. :

// The date looks like this in the JSON 
"someEpochDateTime": 1428785212000,

// I thought I could work around it using the following code, however
// I get a warning saying someEpochDateTime is never set.

[DataMember(Name = "someEpochDateTime")]
private long someEpochDateTime;

public DateTime test
{
get { return DateTimeConverter.FromUnixTime(someEpochDateTime); }
}

Using FromUnixTime

Community
  • 1
  • 1
user1970794
  • 253
  • 3
  • 16

2 Answers2

0

like this you can create datereturn property this will return date

     [DataContract]
     public class Mycontractclass
     {     
         // Apply the DataMemberAttribute to the property.
        [DataMember]
        public DateTime datereturn
        {
           get
           {
              return this.dateCreated.HasValue
                 ? this.dateCreated.Value
                 : DateTime.Now;
           }

           set { this.dateCreated = value; }
        }

        private DateTime? dateCreated = null;
    }
MMM
  • 3,132
  • 3
  • 20
  • 32
0

Apparently my last edit actually works as a solution, I just get a compiler warning for some reason.

[DataMember(Name = "someEpochDateTime")]
private long someEpochDateTime;

public DateTime test
{
    get { return DateTimeConverter.FromUnixTime(someEpochDateTime); }
}
user1970794
  • 253
  • 3
  • 16