C# 文本转日期格式

private object GetExcelDate(object dateText)
	{
		if (dateText.IsNullOrEmptyOrWhiteSpace())
		{
			return dateText;
		}
		string text = dateText.ToString();
		if (!text.Contains(".") && DateTime.TryParse(text, out var result))
		{
			return dateText;
		}
		decimal result2 = 0m;
		decimal.TryParse(text, out result2);
		if (result2 > 0m)
		{
			text = DateTime.FromOADate((double)result2).GetString();
			if (!DateTime.TryParse(text, out result))
			{
				return dateText;
			}
			if (result.Year == 1899)
			{
				DateTime now = DateTime.Now;
				result = result.AddYears(now.Year - result.Year);
				result = result.AddMonths(now.Month - result.Month);
				result = result.AddDays(now.Day - result.Day);
			}
			return result;
		}
		return dateText;
	}

你可能感兴趣的:(c#,java,javascript,日期)