using
System;
using
System.Text.RegularExpressions;
public
class
TimeZoneConversionHelper
{
public
static
string
RegexReplaceTime(
string
input,
double
timeZone)
{
string
convertedText =
String
.Empty;
if
((input !=
String
.Empty) && (input !=
null
))
{
string
pattern =
@"\?*(((((0[13578])|([13578])|(1[02]))[\-\/\s]?\b((0[1-9])|([1-9])|([1-2][0-
9])|(3[01])))|((([469])|(11))[\-\/\s]?\b((0[1-9])|([1-9])|([1-2][0-9])|(30)))|((02|2)[\-\/\s]?\b((0[1-
9])|([1-9])|([1-2][0-9]))))[\-\/\s]?\b\d{4})(\s(((0[1-9])|([1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5]
[0-9])\s))([AM|PM|am|pm]{2,2})))?"
;
MatchCollection
matchCollection =
Regex
.Matches(input, pattern);
foreach
(
Match
match
in
matchCollection)
{
DateTime
conversionDateTime = TimeZoneConversion(
Convert
.ToDateTime(match.Value), timeZone);
convertedText = input.Replace(match.ToString(), conversionDateTime.ToString());
}
}
return
convertedText;
}
public
static
DateTime
TimeZoneConversion(
DateTime
utcTime,
double
timeZone)
{
return
utcTime.AddHours(timeZone);
}
}