datetime-format

How do I convert datetime to ISO 8601 in PHP

女生的网名这么多〃 提交于 2019-11-26 08:01:55
问题 How do I convert my time from 2010-12-30 23:21:46 to ISO 8601 date format? (-_-;) 回答1: Object Oriented This is the recommended way. $datetime = new DateTime('2010-12-30 23:21:46'); echo $datetime->format(DateTime::ATOM); // Updated ISO8601 Procedural For older versions of PHP, or if you are more comfortable with procedural code. echo date(DATE_ISO8601, strtotime('2010-12-30 23:21:46')); 回答2: After PHP 5 you can use this: echo date("c"); form ISO 8601 formatted datetime. http://ideone.com

Convert Epoch seconds to date and time format in Java

Deadly 提交于 2019-11-26 05:58:40
问题 I have seconds since 1970 january 1 UTC (Epoch time). 1320105600 I need to convert that seconds into date and time in below format. Friday,November 4,2011 5:00,AM How can I achieve this? 回答1: In case you're restricted to legacy java.util.Date and java.util.Calendar APIs, you need to take into account that the timestamps are interpreted in milliseconds, not seconds. So you first need to multiply it by 1000 to get the timestamp in milliseconds. long seconds = 1320105600; long millis = seconds *

Python datetime to string without microsecond component

梦想与她 提交于 2019-11-26 04:29:57
问题 I\'m adding UTC time strings to Bitbucket API responses that currently only contain Amsterdam (!) time strings. For consistency with the UTC time strings returned elsewhere, the desired format is 2011-11-03 11:07:04 (followed by +00:00 , but that\'s not germane). What\'s the best way to create such a string ( without a microsecond component) from a datetime instance with a microsecond component? >>> import datetime >>> print unicode(datetime.datetime.now()) 2011-11-03 11:13:39.278026 I\'ll

AngularJS - convert dates in controller

非 Y 不嫁゛ 提交于 2019-11-26 03:08:49
问题 Could anyone please suggest me how to convert date from this 1387843200000 format into this 24/12/2013 inside my controller ? Just FYI my dates are stored in this way & when binding to edit form with input type=\"date\" field is not being populated at all. #Plunker demo here. EditCtrl app.controller(\"EditCtrl\", [ \"$scope\", \"$filter\", \"db\" function ($scope, $filter, db){ // this gets me an item object var item = db.readItem(); // item date = 1387843200000 // this returns undefined item

How to convert milliseconds into human readable form?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 03:04:35
问题 I need to convert an arbitrary amount of milliseconds into Days, Hours, Minutes Second. For example: 10 Days, 5 hours, 13 minutes, 1 second. 回答1: Well, since nobody else has stepped up, I'll write the easy code to do this: x = ms / 1000 seconds = x % 60 x /= 60 minutes = x % 60 x /= 60 hours = x % 24 x /= 24 days = x I'm just glad you stopped at days and didn't ask for months. :) Note that in the above, it is assumed that / represents truncating integer division. If you use this code in a

Formatting DateTime object, respecting Locale::getDefault()

拜拜、爱过 提交于 2019-11-26 02:38:21
问题 I have a DateTime object which I\'m currently formating via $mytime->format(\"D d.m.Y\") Which gives me exactly the format I need: Tue 5.3.2012 The only missing point is the correct language. I need German translation of Tue ( Tuesday ), which is Die ( Dienstag ). This gives me the right locale setting Locale::getDefault() But I don\'t know how to tell DateTime::format to use it. Isn\'t there a way to do something like: $mytime->format(\"D d.m.Y\", \\Locale::getDefault()); 回答1: That's because

Convert DataFrame column type from string to datetime, dd/mm/yyyy format

為{幸葍}努か 提交于 2019-11-26 01:38:43
问题 How can I convert a DataFrame column of strings (in dd/mm/yyyy format) to datetimes? 回答1: The easiest way is to use to_datetime: df['col'] = pd.to_datetime(df['col']) It also offers a dayfirst argument for European times (but beware this isn't strict). Here it is in action: In [11]: pd.to_datetime(pd.Series(['05/23/2005'])) Out[11]: 0 2005-05-23 00:00:00 dtype: datetime64[ns] You can pass a specific format: In [12]: pd.to_datetime(pd.Series(['05/23/2005']), format="%m/%d/%Y") Out[12]: 0 2005

Custom date format with jQuery validation plugin

天涯浪子 提交于 2019-11-26 00:32:24
问题 How can I specify a custom date formate to be validated with the Validation Plugin for jQuery? 回答1: You can create your own custom validation method using the addMethod function. Say you wanted to validate "dd/mm/yyyy": $.validator.addMethod( "australianDate", function(value, element) { // put your own logic here, this is just a (crappy) example return value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/); }, "Please enter a date in the format dd/mm/yyyy." ); And then on your form add: $('#myForm')

Parse DateTime string in JavaScript

故事扮演 提交于 2019-11-25 23:35:33
问题 Does anyone know how to parse date string in required format dd.mm.yyyy ? 回答1: See: Mozilla Core JavaScript Reference: Date object Mozilla Core JavaScript Reference: String.Split Code: var strDate = "03.09.1979"; var dateParts = strDate.split("."); var date = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]); 回答2: If you are using jQuery UI, you can format any date with: <html> <body> Your date formated: <span id="date1"></span><br/> </body> </html> var myDate = '30.11.2011'; var

Given a DateTime object, how do I get an ISO 8601 date in string format?

廉价感情. 提交于 2019-11-25 23:01:21
问题 Given: DateTime.UtcNow How do I get a string which represents the same value in an ISO 8601-compliant format? Note that ISO 8601 defines a number of similar formats. The specific format I am looking for is: yyyy-MM-ddTHH:mm:ssZ 回答1: Note to readers: Several commenters have pointed out some problems in this answer (related particularly to the first suggestion). Refer to the comments section for more information. DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz"); This gives you a