Home > Blockchain >  Razor-pages ParseExact string
Razor-pages ParseExact string

Time:01-20

I am trying to format this string into a "MM-dd-yyyy" I am not sure what I am doing wrong I know its a string that I need to get ParseExact into a date.

20210921124857177 is the value and the error I am getting is not in an acceptable format

   @{var contentLastModified = @item.GetValue("LastModified").ToString(); 
                    DateTime dateTimeLastModified = DateTime.ParseExact(contentLastModified, "MM-dd-yyyy",CultureInfo.InvariantCulture);
   }

   <div>LastModified : @dateTimeLastModified</div>

CodePudding user response:

The value 20210921124857177 does not match the format MM-dd-yyyy.

At a guess, the format you need would be yyyyMMddHHmmssfff:

DateTime dateTimeLastModified = DateTime.ParseExact(contentLastModified, "yyyyMMddHHmmssfff", CultureInfo.InvariantCulture);

/* Result: 2021-09-21 12:48:57 */
  •  Tags:  
  • Related