Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 974177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:23:38+00:00 2026-05-16T03:23:38+00:00

The DateTimeOffset property I have in this class doesn’t get rendered when the data

  • 0

The DateTimeOffset property I have in this class doesn’t get rendered when the data is represented as Xml. What do I need to do to tell the Xml serialization to render that proper as a DateTime or DateTimeOffset?

[XmlRoot("playersConnected")]
public class PlayersConnectedViewData
{
    [XmlElement("playerConnected")]
    public PlayersConnectedItem[] playersConnected { get; set; }
}

[XmlRoot("playersConnected")]
public class PlayersConnectedItem
{
    public string name { get; set; }
    public DateTimeOffset connectedOn { get; set; }  // <-- This property fails.
    public string server { get; set; }
    public string gameType { get; set; }
}

and some sample data…

<?xml version="1.0" encoding="utf-8"?>
<playersConnected 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <playerConnected>
    <name>jollyroger1000</name>
    <connectedOn />
    <server>log1</server>
    <gameType>Battlefield 2</gameType>
  </playerConnected>
</playersConnected>

Update

I’m hoping there might be a way through an Attribute which I can decorate on the property…

Bonus Question

Any way to get rid of those two namespaces declared in the root node? Should I?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:23:39+00:00Added an answer on May 16, 2026 at 3:23 am

    I’ve ended up just doing this…

    Added the two extension methods …

    public static double ToUnixEpoch(this DateTimeOffset value)
    {
        // Create Timespan by subtracting the value provided from 
        //the Unix Epoch then return the total seconds (which is a UNIX timestamp)
        return (double)((value - new DateTime(1970, 1, 1, 0, 0, 0, 0)
            .ToLocalTime())).TotalSeconds;
    }
    
    public static string ToJsonString(this DateTimeOffset value)
    {
        return string.Format("\\/Date({0})\\/", value.ToUnixEpoch());
    }
    

    Modified the ViewData class…

    [XmlRoot("playersConnected")]
    public class PlayersConnectedItem
    {
        public string name { get; set; }
        public string connectedOn { get; set; }
        public string server { get; set; }
        public string gameType { get; set; }
    }
    

    Changed how I set the viewdata properties…

    var data = (from q in connectedPlayerLogEntries
                select new PlayersConnectedItem
                           {
                               name = q.ClientName,
                               connectedOn =  q.CreatedOn.ToJsonString(),
                               server = q.GameFile.UniqueName,
                               gameType = q.GameFile.GameType.Description()
                            });
    

    Done. Not sure if that’s the best way .. but now that viewdata property has the same values for either Json or Xml.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You didn't say which ORM you're using so I assumed… May 16, 2026 at 12:06 pm
  • Editorial Team
    Editorial Team added an answer If anyone is interested... this seems to work. Another thumbs… May 16, 2026 at 12:06 pm
  • Editorial Team
    Editorial Team added an answer echo hello! | lynx -stdin May 16, 2026 at 12:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a bunch of entity class (generated by Linq to SQL) with a
I have a domain model object which has properties of type System.DateTimeOffset. I'm using
I have this <%=Model.StartDate%> <%=Html.Hidden(StartDate, Model.StartDate)%> it outputs: 2010-05-11 11:00:00 +01:00 <input type=hidden value=2010-03-17
Working to get DateTimes for any time zone. I'm using DateTimeOffset, and a string,
I am trying to use the new DATETIMEOFFSET data type in SQL 2008 but
I want to store a a c# DateTimeOffset value in a SQL Server 2005
Is there any supported way of mapping datetimeoffset the new datatype in SQL 2008
I am looking into using the datetimeoffset for SQL Server 2008. According to the
I don't think this should be in my view, but instead handled by the
Porting over an application to use NHibernate from a different ORM. I've started to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.