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);

}

}

Date in C# From String Date in C# From String Reviewed by Leo on Februari 21, 2023 Rating: 5

Tidak ada komentar

About me

About Me

My name is Joanne Doe, a lifestyle photographer and blogger currently living in Osaka, Japan. I write my thoughts and travel stories inside this blog.