Prince
Prince

Reputation: 43

C# Date Converting form /Date(1453154400000)/ format to normal date (DD/MM/YY)

l am importing an excel file into a hashtable then passing the hashtable to the front end as part of a WebServiceResponse response for display. Data displays for some files but for some files that l try to import the date is shown as /Date(1453154400000)/.

am looking for a way to convert this format to DD/MM/YYYY date format

   public WebServiceResponse ReadFile(string fileName, string inputFormat)
    {
        string filePath = Server.MapPath("~/upload/");

      string filePath = Server.MapPath("~/upload/");

        string strConnection =
            string.Format(
      "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0}{1};" 
           + "Extended Properties=\"Excel 
      12.0;HDR=NO;IMEX=1;ImportMixedTypes=Text;\"", filePath, fileName);

        var jsonArray = new List<Hashtable>();


     string. 
        using (var cnConnection = new OleDbConnection(strConnection))
        { 
            cnConnection.Open();

            try
            {

                var cmdSelectSections = new 
       OleDbCommand(string.Format("SELECT * FROM [{0}]", "Sheet1$"), 
           cnConnection);

                OleDbDataReader drdSections = 
             cmdSelectSections.ExecuteReader();

                // Import excel rows into XML files 
                if (drdSections != null)
                {
                    while (drdSections.Read())
                    {

                        var record = new Hashtable();

                        for (int j = 0; j < drdSections.FieldCount; j++)
                        {
     record.Add("Col" + j.ToString(CultureInfo.InvariantCulture), 
                 drdSections[j]);
                        }

                        jsonArray.Add(record);
                        //}
                    }
                }
            }
            finally
            {

                cnConnection.Close();
            }

        }
        var coldef = new string[20]; 
        var numberOfCols = jsonArray[0].Count; 
        var i = 0; 
        var result = new Hashtable
                         {
                             {"colDef", coldef},
                             {"data", jsonArray}
                         };

        return WebServiceResponse.PassResponse(result);
    }

Upvotes: 0

Views: 257

Answers (1)

Md. Abdul Alim
Md. Abdul Alim

Reputation: 689

You can try with this

var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var date = epoch.AddMilliseconds(1453154400000).ToString("dd/MM/yy");

I hope you will get your correct time

Upvotes: 1

Related Questions