In JavaScript, I have dates in an array ( named aLabels) that looks like:  /Date(1485703380827)/,/Date(1485703410233)/,.... to 96 entries.  How to I convert/ format them so I can use them in a label?  I tried:  Looping through the array to try to format each date. But for each iteration, before I am able to modify it, I get: Invalid Date.            // Create a holding array.           var formatttedDateTime = new Array();            // Loop thru the label array to format each entry into a formatted data/time.           for (i = 0; i &lt; aLabels.length; i++)           {               var utcDateVal = new Date(aLabels[i]);                // For testing.               alert("original date " + utcDateVal);                var actualDate = new Date(utcDateVal.getTime() + (utcDateVal.getTimezoneOffset() * 60 * 1000))               // Load the formatted date/time array.              formatttedDateTime[i] = actualDate;           }
446
I'm taking my first crack at  with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string back that looks like this:  /Date(1224043200000)/   From someone totally new to JSON - How do I format this to a short date format? Should this be handled somewhere in the jQuery code? I've tried the jQuery.UI.datepicker plugin using $.datepicker.formatDate() without any success.  FYI: Here's the solution I came up with using a combination of the answers here:  function getMismatch(id) {   $.getJSON("Main.aspx?Callback=GetMismatch",     { MismatchId: id },      function (result) {       $("#AuthMerchId").text(result.AuthorizationMerchantId);       $("#SttlMerchId").text(result.SettlementMerchantId);       $("#CreateDate").text(formatJSONDate(Date(result.AppendDts)));       $("#ExpireDate").text(formatJSONDate(Date(result.ExpiresDts)));       $("#LastUpdate").text(formatJSONDate(Date(result.LastUpdateDts)));       $("#LastUpdatedBy").text(result.LastUpdateNt);       $("#ProcessIn").text(result.ProcessIn);     }   );    return false; }  function formatJSONDate(jsonDate) {   var newDate = dateFormat(jsonDate, "mm/dd/yyyy");   return newDate; }   This solution got my object from the callback method and displayed the dates on the page properly using the date format library.
80895
Why does this javascript return 108 instead of 2008? it gets the day and month correct but not the year?  myDate = new Date(); year = myDate.getYear();   year = 108?
81396
I am trying to convert a date with individual parts such as 12, 1, 2007 into a datetime in SQL Server 2005. I have tried the following:  CAST(DATEPART(year, DATE)+'-'+ DATEPART(month, DATE) +'-'+ DATEPART(day, DATE) AS DATETIME)   but this results in the wrong date. What is the correct way to turn the three date values into a proper datetime format.
29212
Anyone know a simple way using Java calendar to subtract X days from a date?  I have not been able to find any function which allows me to directly subtract X days from a date in Java. Can someone point me to the right direction?
1762
Throughout the site abbreviated dates are used (Apr 21 at 9:12). This works great for dates within the current year but it seems that as the years roll by it'll become important to include the year in the date. I am not sure that having the time is of value for a post that is a year old. Maybe at a certain threshold replacing the time with the year is appropriate.
88277
I constantly have problems working with dates in Excel, I must be doing something wrong but I don't understand what.  I have a spreadsheet, exported from our exchange server, that contains a column with dates on. They have come out in US format even though I'm in the UK.   The column in question looks like this  04/08/2012 04/09/2009 04/01/2010 04/21/2011 04/05/2012 08/30/2009 08/29/2010 08/28/2011   In Excel, I have highlighted the column and selected Format Cells.... In this dialog box, I have selected the Date, selected English (United States) as the locale and chosen the matching date format from the list. I hit OK and try to sort the data by this column.   In the sort dialogue I choose this column, select sort on Values but the order only gives me options for A to Z, not oldest to newest as I would expect.  This in turn sorts the date data by the first two digits.  I am aware I could re-format this data to ISO and then the A to Z sort would work but I shouldn't have too, I'm obviously missing something. What is it?  EDIT: I messed up the bounty but this should have gone to @r0berts answer, his first suggestion of Text to Columns with no delimiter and choosing 'MDY' as the type of data works. Additionally, if you have a time (i.e. 04/21/2015 18:34:22), you need to first get rid of the time data. However after that the method suggested by @r0berts works fine.
18574
I'm trying to convert a date string into an age.  The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is.  I have sucessfully converted the date using:  &gt;&gt;&gt; time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200") (2008, 11, 17, 1, 45, 32, 0, 322, -1)   For some reason %z gives me an error for the +0200 but it doesn't matter that much.  I can get the current time using:  &gt;&gt;&gt; time.localtime() (2009, 2, 3, 19, 55, 32, 1, 34, 0)   but how can I subtract one from the other without going though each item in the list and doing it manually?
13722
I'm looking for a good JavaScript equivalent of the C/PHP printf() or for C#/Java programmers, String.Format() (IFormatProvider for .NET).  My basic requirement is a thousand separator format for numbers for now, but something that handles lots of combinations (including dates) would be good.  I realize Microsoft's  library provides a version of String.Format(), but we don't want the entire overhead of that framework.
26496
I want to display dates in the format: short day of week, short month, day of month without leading zero but including "th", "st", "nd", or "rd" suffix.  For example, the day this question was asked would display "Thu Oct 2nd".  I'm using Ruby 1.8.7, and  just doesn't seem to do this.  I'd prefer a standard library if one exists.
600
How do I get the number of days between two dates in JavaScript? For example, given two dates in input boxes:  &lt;input id="first" value="1/1/2000"/&gt; &lt;input id="second" value="1/1/2001"/&gt;  &lt;script&gt;   alert(datediff("day", first, second)); // what goes here? &lt;/script&gt;
119405
Does anyone know how to convert string time formats in ArcMap v10.2 from 12-hour to 24-hour using a simple query in the Field Calculator? i.e. NO Python, NO editing in Excel, NO changing my Windows PC settings, etc...  This is a successful calculation I used (which I found on a discontinued forum) to convert my dates from MM/DD/YYYY to YYYY/MM/DD:  year([DateFld]) &amp; "/" &amp; Month([DateFld]) &amp; "/" &amp; Day([DateFld])  Perhaps there is some sort of modification that I could make to the above calculation that would change my times to 24-hour?  I've searched for an answer everywhere and played around with it without any luck, but I would like for the times to be in h:mm:ss format.  Forgot to mention that this is a regular shapefile, not part of a GDB.
17519
I have a string containing the , and I need to convert it to a Java Date object.  String date = "1081157732"; DateFormat df = new SimpleDateFormat(""); // This line try {   Date expiry = df.parse(date);  } catch (ParseException ex) {   ex.getStackTrace(); }   The marked line is where I'm having trouble. I can't work out what the argument to SimpleDateFormat() should be, or even if I should be using SimpleDateFormat().
82739
In an application when you are showing a date to someone (and you don't know their preferred format), what date format should you use?  USA or Rest-of-the-world?     For reference if anyone is not sure what these formats are, today's date would be:   USA = 10/07/2011 or October 7, 2011   Rest-of-the-world = 07/10/2011 or 7 October 2011   Assuming an equal probability that a user is from the USA or outside the USA, which format should I use?  Note, this question was largely triggered by the comments in .
1510
I'm working with a date in this format: yyyy-mm-dd.  How can I increment this date by one day?
45640
I have some issues about choosing how to align a Date/time data type in a field. Which is the best way to align this type of date and why? Right or left? P.S We use WPF.  [------25.03.2015] or [25.03.2015------]  Thank you :)
76797
I'm using a DateTime in C# to display times. What date portion does everyone use when constructing a time?  E.g. the following is not valid because there is no zero-th month or zero-th day:  // 4:37:58 PM DateTime time = new DateTime(0, 0, 0, 16, 47, 58);   Do I use COM's zero date?  // 4:37:58 PM DateTime time = new DateTime(1899, 12, 30, 16, 47, 58);   Or perhaps SQL Server's?  //4:37:58 PM DateTime time = new DateTime(1900, 1, 1, 16, 47, 58);   I realize it's arbitrary, since I'll be ignoring the date portions in code, but it would still be nice to be able to use:  DateTime duration = time2 - time1;     Answer  I think I like MinValue   DateTime time = DateTime.MinValue.Date.Add(new TimeSpan(16, 47, 58));     Note: I can't use a TimeSpan, because that doesn't store times of the day. And the reason I know that is because there's no way to display its contents as a time.  Which is to say that TimeSpan records a span of time, not a time of day, e.g.:  TimeSpan t = new TimeSpan(16, 47, 58); t.ToString();   returns a span of time in the format hours:minutes:seconds, e.g.:  16:47:58   rather than a time:  4:47:58 PM    (United States) 04:47:58 nm   (South Africa) 4:47:58.MD    (Albania) 16:47:58      (Algeria) 04:47:58 م    (Bahrain) PM 4:47:58    (Singapore) 下午 04:47:58  (Taiwan) 04:47:58 PM   (Belize) 4:47:58 p.m.  (New Zealand) 4:47:58 μμ    (Greece) 16.47.58      (Italy) 오후 4:47:58   (Korea) 04:47:58 ب.ظ  (Iran) ਸ਼ਾਮ 04:47:58   (India) 04:47:58 p.m. (Argentina) etc   In other words, there is a difference between a timespan, and a time. And also realize that TimeSpan doesn't provide a mechanism to convert a span of time into a time of day - and there is a reason for that.
107508
I am working on a form widget for users to enter a time of day into a text input (for a calendar application). Using JavaScript (we are using jQuery FWIW), I want to find the best way to parse the text that the user enters into a JavaScript Date() object so I can easily perform comparisons and other things on it.  I tried the parse() method and it is a little too picky for my needs. I would expect it to be able to successfully parse the following example input times (in addition to other logically similar time formats) as the same Date() object:   1:00 pm 1:00 p.m. 1:00 p 1:00pm 1:00p.m. 1:00p 1 pm 1 p.m. 1 p 1pm 1p.m. 1p 13:00 13   I am thinking that I might use regular expressions to split up the input and extract the information I want to use to create my Date() object. What is the best way to do this?