Date in C# From String
using System;
public class Program
{
public static void Main()
{
for(var i=1; i < 24; i++){
string b = "";
b = i.ToString();
if(i < 10){
b = "0" + i.ToString();
}
//will replace dt Modify
string dtModify = "22/02/2023 [object]:00:00";
dtModify = dtModify.Replace("[object]", b);
DateTime dt = DateTime.ParseExact(dtModify, "dd/MM/yyyy HH:mm:ss", new System.Globalization.CultureInfo("en-US"));
DateTime result = CheckDate(dt);
if (dt.Hour < 9 || dt.Hour > 18){
Console.WriteLine(result + " Not Change");
}else{
Console.WriteLine(result);
}
}
}
public static DateTime CheckDate(DateTime dt) {
if (dt.Hour < 9 || dt.Hour > 18) return dt;
int hour = dt.Hour - 8;
int calculate = (hour * 6) + 6 ;
return dt.AddMinutes(calculate);
}
}
Tidak ada komentar