get File Date Time Style - CSharp System.IO

CSharp examples for System.IO:File Time

Description

get File Date Time Style

Demo Code


using System.Text;
using System.Linq;
using System.IO;//from  ww w  .j  a  v a2  s. co m
using System.Collections.Generic;
using System;

public class Main{
    public static string getFileDateTimeStyle(DateTime? dateTime = null)
      {
         string fileDateStyle = string.Empty;

         DateTime dt = (dateTime.HasValue ? dateTime.Value : DateTime.Now);
         int year = (dt.Year % 1000);
         int month = dt.Month;
         int day = dt.Day;
         int hour = dt.Hour;
         int min = dt.Minute;
         int sec = dt.Second;

         fileDateStyle += year.ToString().PadLeft(2, '0');
         fileDateStyle += month.ToString().PadLeft(2, '0');
         fileDateStyle += day.ToString().PadLeft(2, '0');
         fileDateStyle += hour.ToString().PadLeft(2, '0');
         fileDateStyle += min.ToString().PadLeft(2, '0');
         fileDateStyle += sec.ToString().PadLeft(2, '0');

         return fileDateStyle;
      }
}

Related Tutorials