Important Point: First thing that your value does not fit in the integer datatype, because value gets overflow. Int accepts value within -2,147,483,648 to 2,147,483,647. Try to store that value in long
When you try DateTime.ParseExact() it will throw an error input string was not recognized as a valid datetime
So you can extract the each individual part using substring
Like this
long data = 20160513225918;
int year = int.Parse(data.ToString().Substring(0, 4));
int month = int.Parse(data.ToString().Substring(4, 2));
int day = int.Parse(data.ToString().Substring(6, 2));
int hour = int.Parse(data.ToString().Substring(8, 2));
int minute = int.Parse(data.ToString().Substring(10, 2));
int second = int.Parse(data.ToString().Substring(12, 2));
//bellow line will get you "2016-05-13 22:59:18"
var date = new DateTime(year, month, day, hour, minute, second).ToString("yyyy-MM-dd HH:mm:ss");
The first parameter inside Substring is start index
2
Answers
Important Point: First thing that your value does not fit in the integer datatype, because value gets overflow.
Int
accepts value within -2,147,483,648 to 2,147,483,647. Try to store that value inlong
When you try
DateTime.ParseExact()
it will throw an error input string was not recognized as a valid datetimeSo you can extract the each individual part using
substring
Like this
You can just use basic arithmetic for this, no string parsing necessary
dotnetfiddle