Datetime format with milliseconds

The datetime formatting for milliseconds is not working.

I’ve tried the following:
dateStyle.Custom = “m/d/yyyy h:mm:ss.0 AM/PM”;
dateStyle.Custom = “m/d/yyyy h:mm:ss.000 AM/PM”;

Hi,

Thanks for your posting and using Aspose.Cells.

Please provide us your sample excel file which should have a datetime value in your required format. You can create it manually using Microsoft Excel and attach it here. It will help us investigate this issue and we will provide you a sample code/date format pattern string to resolve this issue.

Thanks for your cooperation.

Here is the code:

var dateStyle = wb.CreateStyle();

dateStyle.Custom = “m/d/yyyy h:mm:ss AM/PM”;

var dateStyleFlag = new StyleFlag { NumberFormat = true };





// Dates need to appear correctly since calling ConvertStringToNumericValue messes them up

foreach (Cell c in sheet.Cells.Rows[0])

{

if(c.Value.ToString().ToUpper().Contains(“UTC”) || c.Value.ToString().Trim().ToUpper().Equals(“TIME”)) sheet.Cells.Columns[c.Column].ApplyStyle(dateStyle, dateStyleFlag);

}



sheet.AutoFitColumns();

Hi Annette,


Thank you for sharing your code & sample spreadsheet.

We have evaluated the presented scenario while using the latest version of Aspose.Cells for .NET (Latest Version) , and we are unable to see any problem in the resultant spreadsheet (attached). Please give a try to the latest version while using the simple code snippet as provided below. Please note, the following code sets the format for the Column U. Once you have tested the case with one column, you can extended the feature for all required columns. This way, you will be able to troubleshoot if there is any problem in finding the correct column to be formatted.

C#

var book = new Workbook(“D:/None_20150720_1404070144.xlsx”);
Column column = book.Worksheets[0].Cells.Columns[20];
var style = book.CreateStyle();
style.Custom = “m/d/yyyy h:mm:ss.000 AM/PM”;
column.ApplyStyle(style, new StyleFlag() { NumberFormat = true});
book.Worksheets[0].AutoFitColumns();
book.Save(“D:/output.xlsx”);