Having issue with a data converstion of iso datetime format PT5H44M15.957S

Manu Michael Samuel 131 Reputation points
2020-12-17T07:22:42.81+00:00

Hi,
I was trying to convert a datatype time column in dataset which the data is in 05:44:09.57. While I convert the dataset to xml using datset.GetXml(); The value 05:44:09.57 is converted to PT5H44M15.957S. This section was doing was in UWP App.
Thank you.

Developer technologies | Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
    2020-12-25T08:45:56.897+00:00

    Hello @Manu Michael Samuel , Welcome to Microsoft Q&A,

    During the testing, we can't reproduce this problem, but for this problem, you could convert PT5H44M15.957S to 05:44:09.57 manually.

    For example:

    public static class TimeTranslator  
    {  
        public static string ToTimeSpanString(string raw)  
        {  
            if (string.IsNullOrWhiteSpace(raw))  
                return "";  
            else  
                raw = raw.ToUpperInvariant();  
            var newValue =   new StringBuilder();  
            foreach (var c in raw)  
            {  
                if (" -0123456789".Contains(c))  
                {  
                    newValue.Append(c);  
                }  
                else  
                {  
                    var result = TranslateToNumber(c);  
      
                    if (result != null)  
                        newValue.Append(result);  
      
                }  
            }  
            return newValue.ToString();  
        }  
      
        static string TranslateToNumber(char c)  
        {  
            if ("PT".Contains(c))  
                return string.Empty;  
            else if ("H".Contains(c))  
                return ":";  
            else if ("M".Contains(c))  
                return ":";  
            else if ("S".Contains(c))  
                return string.Empty;  
            else if (".".Contains(c))  
                return ".";  
            return null;  
        }  
    }  
    

    Usage

      var time = TimeTranslator.ToTimeSpanString("PT5H44M15.957S");  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.