datetime-format

DateTime issue when global culture of the server is different on different servers

六眼飞鱼酱① 提交于 2019-11-28 11:20:34
My website is hosted on multiple servers at different locations Everywhere the Culture of the data format is different- we use mm/dd/yyyy format every where but incase some server has the culture set to dd/mm/yyyy then our website generates Datetime exception. You should be specifying what culture you want to use whenever you convert a string to a date. The culture you should be using depends on what culture the dates are formatted as. For example, if all dates you are parsing are formatted as Slovak : String s = "24. 10. 2011"; Then you need to parse the string as though it were in Slovak

How to fast convert different time formats in large data frames?

纵然是瞬间 提交于 2019-11-28 10:21:18
问题 I want to calculate length in different time dimensions but I have problems dealing with the two slightly different time formats in my data frame column. The original data frame column has about a million rows with the two formats (shown in the example code) mixed up . Example code: time <- c("2018-07-29T15:02:05Z", "2018-07-29T14:46:57Z", "2018-10-04T12:13:41.333Z", "2018-10-04T12:13:45.479Z") length <- c(15.8, 132.1, 12.5, 33.2) df <- data.frame(time, length) df$time <- format(as.POSIXlt

C# : Convert datetime from string with different format

戏子无情 提交于 2019-11-28 08:59:32
问题 If my string is 26/01/2011 00:14:00 but my computer set United state format (AM:PM) How to convert my string into Datetime ? I try Convert.ToDateTime() but it cause error. 回答1: As the others have said, you can use DateTime.TryParseExact, but you also seem to have a European culture format in your date. It might not hurt to make an attempt to use that to perform the conversion: CultureInfo enGB = new CultureInfo("en-GB"); string dateString; DateTime dateValue; // Parse date with no style flags

DateTime Conversion and Parsing DateTime.Now.ToString(“MM/dd/yyyy hh:mm:ss.fff”)

余生长醉 提交于 2019-11-28 08:47:32
问题 I store some DateTime in a CSV log with: DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff") When I try to read it I found something like: "05/15/2012 10:09:28.650" The problem is when I try to cast it as a DateTime again... DateTime.Parse("05/15/2012 10:09:28.650"); Throws an Exception "Invalid DateTime" or something like that... How can I properly re-read the DateTime? 回答1: You can use DateTime.ParseExact: string format = "MM/dd/yyyy hh:mm:ss.fff"; DateTime d = DateTime.ParseExact("05/15/2012

Parse CIM_DateTime to .Net DateTime

安稳与你 提交于 2019-11-28 08:40:23
问题 My application is receiving some date information from WMI. This in the form of strings with the following format: yyyymmddHHMMSS.mmmmmmsUUU For more details on this format, see here. I'm interested in parsing everything before the period. I have the following code: string testDate = "20010701212212"; // July, 01, 2001 21:22:12, in the format specified above string format = "yyyyMMddHHmmSS"; CultureInfo culture = CultureInfo.InvariantCulture; DateTime newDate = DateTime.ParseExact(date,

Datetime format from iPhone settings and GMT offset

情到浓时终转凉″ 提交于 2019-11-28 06:54:14
问题 I have string with date time format e.g.: 2013-05-28 10:56:31 How can I format this string to the iPhone default format? (in iPhone settings) And how to set datetime in GMT plus time shift offset (set in iphone too). e.g. GMT+1 Is this possible? 回答1: You can use NSDateFormatter to achieve this. NSString *dateString = @"2013-05-28 10:56:31"; NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; //Special Locale for fixed dateStrings NSLocale *locale = [[NSLocale alloc

Date conversion from C# to MySql Format

孤人 提交于 2019-11-28 05:55:54
问题 How to convert C# datetime to MySql Datetime format. I am getting value from text box like 7/27/2011 this format. But i want to convert in this format 2011-7-27. So here i am stuking. Please help me. My objective is to filter the record between two dates and show in a listview control in asp.net. Here is my code: DateTime dt1 = Convert.ToDateTime(txtToDate.Text); DateTime dt2 = Convert.ToDateTime(txtFromDate.Text); lvAlert.DataSource = facade.GetAlertsByDate(dt1, dt2); lvAlert.DataBind(); 回答1

Why is datetime.strptime not working in this simple example?

﹥>﹥吖頭↗ 提交于 2019-11-28 05:38:48
I'm using strptime to convert a date string into a datetime . According to the linked page, formatting like this should work: >>> # Using datetime.strptime() >>> dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M") My code is: import datetime dtDate = datetime.strptime(sDate,"%m/%d/%Y") where sDate = "07/27/2012" . (I understand, from the same page, that %Y is "Year with century as a decimal number." ) I have tried putting the actual value of sDate into the code: dtDate = datetime.strptime("07/27/2012","%m/%d/%Y") but this does not work. The error I get is: AttributeError: 'module'

ISO8601 with milliseconds in json using Jackson

冷暖自知 提交于 2019-11-28 03:56:42
问题 import com.fasterxml.jackson.databind.util.ISO8601DateFormat; objectMapper.setDateFormat(new ISO8601DateFormat()); Nice but this ignores milliseconds, how can I get them in the dates without using the non-thread-safe SimpleDateFormatter ? https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/util/ISO8601DateFormat.java 回答1: ISO8601DateFormat.format calls ISO8601Utils.format(date) , which in turn calls format(date, false, TIMEZONE_Z) - the false

Get just the hour of day from DateTime using either 12 or 24 hour format as defined by the current culture

瘦欲@ 提交于 2019-11-28 03:20:32
问题 .Net has the built in ToShortTimeString() function for DateTime that uses the CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern format. It returns something like this for en-US: "5:00 pm". For a 24 hour culture such as de-DE it would return "17:00". What I want is a way to just return just the hour (So "5 pm" and "17" in the cases above) that works with every culture. What's the best/cleanest way to do this? Thanks! 回答1: // displays "15" because my current culture is en-GB Console