datetime-format

Get culture-specific date with 2 digit year in C#

天大地大妈咪最大 提交于 2019-12-10 13:32:36
问题 I'm updating some code that formats a date to a string using "MM/dd/yy". I need it to be culture aware, but want to keep the two digit year in order to keep the date short. Below is what I came up with, but is there a better way? string dateFormat = culture_Info.DateTimeFormat.ShortDatePattern.Replace("yyyy", "yy"); 回答1: I don't know of any way, no (and I've looked at the formatting reasonably extensively). What you've got obviously still leaves a bit of a nasty taste in the mouth, but I

DateTime string format last digit of year

≡放荡痞女 提交于 2019-12-10 12:56:43
问题 I wonder if there is a better way to get the last digit of a year from a datatime object var date = DateTime.Now; string year1 = date.ToString("y"); //NOT OK return Month year (eg March 2012) char year2 = date.ToString("yy")[1]; //OK return last digit of the year (eg 2) char year3 = date.ToString("yy").Last(); //OK same as above using linq Anyone know if an already predifine format exist for retreiving the last digit of the year? Thanks 回答1: You can do that with simple Modulo math: int digit

What is the Z ending on date strings like 2014-01-01T00:00:00.588Z

僤鯓⒐⒋嵵緔 提交于 2019-12-10 12:32:07
问题 Im doing a fetch to get a date from a database in java (the date should always be 2014-01-01T00:00:00 ). I'm getting the following time returned: 2014-01-01T00:00:00.588Z . My questions is, what is the " 588Z " at the end? and would this number be different the retrieve was done in a different timezone? i.e. would the number 588 be a different number in a different time zone. Thanks for any help I may get. 回答1: The Z stands for the zero UTC offset . If the time is in UTC, add a Z directly

perform action if date change

人走茶凉 提交于 2019-12-10 11:56:10
问题 i need to perform some action if date change. Means at the time of app launch it check the today date, and if today date is change from last 24 hour time,then it will perform some action. Is it possible as we don't need to run background thread. I just want to add some sort of condition in delegate method. like : if on app launch it first save today date and save that date. After again login it will compare that date with current date and if fount its 24 hour change date then it will perform

How to check if a given Date exists in DART?

荒凉一梦 提交于 2019-12-10 11:55:40
问题 If you pass a non-existing/non-real date like: '20181364' (2018/13/64) into DateTime (constructor or parse-method), no exception is thrown. Instead a calculated DateTime is returned. Example: '20181364' --> 2019-03-05 00:00:00.000 How can I check if a given date really exists/is valid? I tried to solve this using DartPad (without success), so no Flutter doctor output required here. void main() { var inputs = ['20180101', // -> 2018-01-01 00:00:00.000 '20181231', // -> 2018-12-31 00:00:00.000

WCF REST JSON with ISO Date Format

南楼画角 提交于 2019-12-10 11:20:34
问题 I got into a big problem supporting ISO dateformat with JSON in my WCF Web service ( Framework 4.0 ). I tried a lot, but no luck yet. Rest Service : [WebInvoke(Method = "PUT", UriTemplate = "/{mvnoid}/{OrderID}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public DataContracts.Feedback InsertOrder(string mvnoid,string OrderID,OrderRequest orderRequest) { OrderRequestManager orderProcessor = new OrderRequestManager(); DataContracts.Feedback feedback =

How to do formally correct parsing of ISO8601 date times in .Net?

独自空忆成欢 提交于 2019-12-09 17:51:56
问题 There are many SO questions and answers regarding parsing of ISO8601 date/times in .NET and C#. However, there doesn't seem to be a 'definitive' answer anywhere, i.e. an answer that presents a formally correct ISO8601 parser that would correctly parse all of the possible format variants within ISO8601 and that would disallow non-ISO8601 variants. This SO answer is the closest match so far... How to create a .NET DateTime from ISO 8601 format 回答1: Okay. Let's start with the limitations you are

Getting a short day name

不想你离开。 提交于 2019-12-09 14:30:51
问题 I was wondering on how to write a method that will return me a string which will contain the short day name, example: public static string GetShortDayName(DayOfWeek day) now if i call: string monday = GetShortDayName(DayOfWeek.Monday); I will get back "mo" if culture is en, or "lu" if culture is at example it. 回答1: You can use DateTimeFormatInfo.AbbreviatedDayNames. For example: string[] names = culture.DateTimeFormat.AbbreviatedDayNames; string monday = names[(int) DayOfWeek.Monday]; 回答2:

DateTime formats used in InvariantCulture

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 08:50:11
问题 I have to pre-validate in Javascript a string that will be a DateTime in c#. The DateTime parse uses InvariantCulture. Does anyone know the DateTime formats defined for InvariantCulture? 回答1: Compiling information from here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings Short Date Pattern ("d"): MM/dd/yyyy Long Date Pattern ("D"): dddd, dd MMMM yyyy Full Date Short Time ("f"): dddd, dd MMMM yyyy HH:mm Full Date Long Time ("F"): dddd, dd MMMM

java.time.DateTimeFormatter : Need ISO_INSTANT that always renders milliseconds

我的梦境 提交于 2019-12-09 05:14:01
问题 I'm trying to cleanup a mix of various code around datetime management to only Java 8 java.time namespace. Right now I have a small issue with the default DateTimeFormatter for Instant. The DateTimeFormatter.ISO_INSTANT formatter only shows milliseconds when they are not equal to zero. The epoch is rendered as 1970-01-01T00:00:00Z instead of 1970-01-01T00:00:00.000Z . I made a unit test to explain the problem and how we need to final dates to be compared one to each other. @Test public void