Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have one big string,in that i have embedded json date format like(\/Date(1425321000000+0530)\/) in many places in my original string.I need to convert this format to normal readable format.

Regards
Vijay
Posted
Comments
vijaykittur 2-Dec-14 3:40am    
I need to extract the date part from my string and i have used in many places this date(json),so in one short it should replace all the date to normal date.
vijaykittur 2-Dec-14 5:28am    
Hi All ,
I found the solution .If anybody having the issue try with this code it will work for any length of string.
//result is the your string in which u want to replace json date formats to normal date format

string p = @"\\/Date\((\d+)\+\d+\)\\/";
MatchEvaluator matchEvaluator = new MatchEvaluator(ConvertJsonDateToDateString);
Regex reg = new Regex(p);
result = reg.Replace(result, matchEvaluator);

private static string ConvertJsonDateToDateString(Match m)
{
string result = string.Empty;
DateTime dt = new DateTime(1970, 1, 1);
dt = dt.AddMilliseconds(long.Parse(m.Groups[1].Value));
dt = dt.ToLocalTime();
result = dt.ToString("yyyy-MM-dd HH:mm:ss");
return result;
}

Regards
Vijay

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900