w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Java Date Conversion
Reference these formats Java Date Format Docs: DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); you are expecting Month at second place while input is placing it on first. try: DateFormat df = new SimpleDateFormat("MM/dd/yyyy");

Categories : Java

Scala String to Java Util Date Conversion
You're trying to parse "E MMM dd HH:mm:ss Z yyyy" formatted date string as "yyyy-MM-dd HH:mm" formatted one, in this line: val date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr) No wonder it fails. Maybe you took the wrong date format for second SimpleDateFormat instance by mistake? Or maybe you're passing wrong parameter to parse() ? edit It looks like you actually wanted to call: val date = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(dat)

Categories : Scala

Java - SimpleDateFormat string to Date to mills conversion
It is supposed to work like that, and I am afraid you'll have to parse this format for yourself. That shouldn't be all that hard though... long millis = 0; String[] numbers = dateString.split("."); millis += Integer.parseInt(numbers[numbers.length-1]) * (int)Math.pow(10,numbers[numbers.length-1].length()-3)); for (int i=2; i<=numbers.length; i++) { millis += Integer.parseInt(numbers[numbers.length-i]) * (int)Math.pow(60,i-1) * 100; } I haven't tested this, but it should provide you with an adequate starting point.

Categories : Java

Retrofit GSON serialize Date from json string into java.util.date
Gson can handle only one datetime format (those specified in builder) plus the iso8601 if parsing with custom format is not possible. So, a solution could be to write your custom deserializer. To solve your problem I defined: package stackoverflow.questions.q18473011; import java.util.Date; public class Foo { Date date; Date created_at; public Foo(Date date, Date created_at){ this.date = date; this.created_at = created_at; } @Override public String toString() { return "Foo [date=" + date + ", created_at=" + created_at + "]"; } } with this deserializer: package stackoverflow.questions.q18473011; import java.lang.reflect.Type; import java.text.*; import java.util.Date; import com.google.gson.*; public class FooDeserializer impleme

Categories : Java

JSON Serializing date in a custom format (Can not construct instance of java.util.Date from String value)
If you want to bind a JSON string to date, this process is called "deserialization", not serialization. To bind a JSON string to date, create a custom date deserialization, annotate "created_date" or its setter with @JsonDeserialize(using=YourCustomDateDeserializer.class) where you have to implement the method "public Date deserialize(...)" to tell Jackson how to convert a string to a date. Enjoy.

Categories : Json

converting JSON date to java script date automatically
What you are wanting is to not have to convert the dates explicitly. The JSON standard doesn't handle javascript dates, so if you want to use javascript dates, the strings representing them will have to be converted. Now, how that happens is up to you. Maybe you are desiring something that uses .NET reflection to automatically construct something for the client-side that can handle the conversion for any object with a DateTime property , and that should be doable, but whether or not somebody has already built a library to do just that, I dunno. That might be cool project to build.

Categories : Javascript

complex json to java object conversion using gson
You need a class structure like this (pseudo-code): class Response String id DataList posts class DataList List<Data> data class Data String message From from String id String created_time DataList comments class From String name String id Note that you can change class names if you want, but you have to keep the attribute names to match the field names in the JSON response. Also note that I've used the same class Data to store the data for the posts and for the comments. This is possible because the data for comments is a subset of the data for posts, so when parsing a comment, Gson will just ignore the attributes created_time and comments... Then parse the JSON with: Gson gson = new Gson(); Response response = gson.fromJson(yourJsonString, Response.clas

Categories : Java

xml to json conversion issue in java, 1st leading zero discarded fom string
looking at the code for XML.java - in particular the stringToValue method which does "Try to convert a string into a number, boolean, or null". The code is below - you can see it tries to parse as a number first, in which case it will trim the leading zeros. To test you could try adding a non-numeric character in your string - I think it would then preserve the leading zeros. It looks like the behaviour you're seeing is baked into the library. Which is not great, even though the docs for the function toJSONObject do warn "Some information may be lost in this transformation because JSON is a data format and XML is a document format" teh codez : // If it might be a number, try converting it. If that doesn't work, // return the string. try { char initial = st

Categories : Java

java.util.Date format conversion yyyy-mm-dd to mm-dd-yyyy
SimpleDateFormat("MM-dd-yyyy"); instead of SimpleDateFormat("mm-dd-yyyy"); because MM points Month, mm points minutes SimpleDateFormat sm = new SimpleDateFormat("MM-dd-yyyy"); String strDate = sm.format(myDate);

Categories : Java

Convert Json date to java calendar
This should work in Java Date date = new Date(Long.parseLong(jsonDate.replaceAll(".*?(\d+).*", "$1"))); the problem with your example is that it's only good for javascript

Categories : Java

iOS : Date conversion results in wrong date
Check this.. NSString *date = @"Aug 9 2013 06:44:01:950AM"; [Date_Converter getDateFromString:date withFormat:@"MMM dd yyyy HH:mm:ss:SSSa"];//only you need to lower the char(yyyy) and it will be fine . And Here is output date = 2013-08-09 00:44:01 +0000 Thanks :)

Categories : Iphone

Conversion from DataSet to JSON ends up wrapping the JSON string with xml tags
I didn't find any good way to return pure JSON from WCF project nor ASMX despite all "Experts" saying "its easy" Add web page to your project (ASPX) which can use your web service as data source and then to serialize the objects from the web service JSON. By using: JavaScriptSerializer serializer = new JavaScriptSerializer(); String myJSON= serializer.Serialize(<your object>); And "myJSON" will hold the JSON. The JavaScriptSerializer can't handle DataTableDataSet so what you can do is to insert DataSet into DataTable and use the following method to convert it to JSON (string) public static string GetDataTableToJSONString(DataTable table) { List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();

Categories : C#

How to let Newtonsoft.Json allow Json DateTime conversion with Timezone info?
I think this link should help you with setting up MVC3 project working with Newtonsoft Json Serializer. For ISO date time formatter you should change the following lines in the JsonNetResult constructor. public JsonNetResult() { Formatting = Formatting.None; var settings = new JsonSerializerSettings(); settings.Converters.Add(new IsoDateTimeConverter()); SerializerSettings = settings; JsonRequestBehavior = JsonRequestBehavior.DenyGet; } You have to derive your controllers from BaseController to use the custom result. hope this helps.

Categories : Json

Incorrect date returned when converting from java.util.date to java.sql.date
This may help you Calendar cal = Calendar.getInstance(); DateFormat df=new SimpleDateFormat("dd/mm/yyyy"); String dateStr="20/04/1961"; Date date = df.parse(dateStr); cal.setTime(date); Date sqlDate = new java.sql.Date(cal.getTime().getTime()); System.out.println("utilDate:" + df.format(date)); System.out.println("sqlDate:" + df.format(sqlDate));

Categories : Java

Checking for a null date before converting to java.sql.date from java.util.date
In your code if (dateBoxArchived.getValue() != null){ sqlDateArchived = dateBoxArchived.getValue().getTime(); convert last line to sqlDateArchived = new Date(dateBoxArchived.getValue().getTime());`

Categories : Java

Date conversion to database date
You can use the inbuilt formatting method as a callback filter public function filters() { return array( 'birthday' => array( array('Format::date',array(':value','Y-m-d')), ), ); } See http://kohanaframework.org/3.1/guide/orm/filters

Categories : PHP

Java: Unable to fix unchecked conversion required java.util.Collection
If oldV is declared as a Vector<String> just use the parameterized version of 'LinkedHashSet': Vector<String> newV = new Vector<String>( new LinkedHashSet<String>(oldV) ) you can also use the annotation @SuppressWarnings if you just want to get rid of the warnings: @SuppressWarnings("unchecked") Vector<String> newV = new Vector<String>( new LinkedHashSet(oldV) );

Categories : Java

Issue with conversion from XML to JSON with json or json-lib
Try using the library from www.json.org instead of net.sf.json.JSON import org.json.JSONObject; import org.json.XML; String xmlString = "<detail>&lt;P&gt;Students should avoid purchasing their textbooks at the first store that they browse. Instead, they should investigate the alternatives offered by other online booksellers. Price isn't the only factor to consider when making an online purchase. Students should also factor in shipping costs and delivery time when making their buying decision.&lt;/P&gt;</detail>"; System.out.println("Initial XML : " + xmlString); JSONObject jsonObj = (XML.toJSONObject(xmlString)); System.out.println("Converted JSON : " + jsonObj.toString()); System.out.println("Back to converted XML : " + XML.toString(jsonObj)); You'll get th

Categories : Java

Expected Lenient behaviour in java date-related classes (JodaTime and/or Java.Date)
You have invalid date pattern at "hh:mm:ss". Date format should be: String format = "yyyy-MM-dd HH:mm:ss"; DateTimeFormat documentation h - clockhour of halfday (1~12) H - hour of day (0~23) With this date pattern all examples works as expected

Categories : Java

Custom JSON to XML conversion using JSON.Net
Internally, Json.Net uses a special JsonConverter called XmlNodeConverter to do the conversion from JSON to XML or vice-versa. This converter does not seem to be very extensible as it is, but you could create your own custom converter using the XmlNodeConverter source code as a starting point, then plug that back into Json.Net. XmlDocument doc = JsonConvert.DeserializeObject<XmlDocument>(json, yourCustomXmlNodeConverter);

Categories : C#

Date conversion in postgress
select to_char(the_date_column, 'mm/yy') from the_table; More details in the manual: http://www.postgresql.org/docs/current/static/functions-formatting.html

Categories : SQL

PHP date conversion from Facebook API
$datum = date("d.m.Y",strtotime($fbdate)); $uhrzeit = date("H:i",strtotime($fbdate)); The date function in PHP is meant to convert a microtime into a date, so you need to convert your string dates to microtimes first.

Categories : PHP

Date format conversion c#
if DateTime expiry_ = ((DateTime)cmd.ExecuteScalar()); this line running without errors you already have Datetime object. So you can directly set it as tpPasswordExpiry.Value =expiry_; But above line will fail if you store datetime as string in database then string _User_modify= (string)cmd.ExecuteScalar(); DateTime dt; if(DateTime.TryParseExact(_User_modify, "dd/MM/YYYY", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { tpPasswordExpiry.Value =dt; }

Categories : C#

SQL date conversion error
You can use something like this to track down the culprit, select * from MyTable where > ISDATE(convert(char(8),MyDateColumn))=0 yes ans: there are some values with only 1 zero in ship_date... This means you will have to either exclude those rows from your query, use a case expression to give bad values a arbitrary value, or fix the data. Also, I am pretty sure you will agree, but I will say it anyway... You should be storing date values in a date/datetime data type. This prevents issues like this and makes things much easier down the road. Also, Instead of storing a value of 0 in the date column, you should store a value of NULL, or have some arbitrary default value.

Categories : SQL

PHP String to date conversion
Is your issue that your "Month" variable is a string instead of an integer, but you are putting it in the date as if it's an integer? 2013-April-5... Try just putting in a 4 instead of April. Update To answer your question, you can have your client updated to have options like <option value="1">January</option>, or update your PHP to process it like: <? $received = $_POST['month']." ".$_POST['day']." ".date("Y"); $date = strtotime($received); $newformat = date('Y F j',$date); echo $newformat; ?> I think that will work.

Categories : PHP

Date format conversion in c#
it is taking 09 as date and 04 as month Yes, because you have said it, change "MM-dd-yyy" to "dd/MM/yyyy h:mm:ss tt" DateTime.ParseExact("04/09/2013 8:09:10 PM","dd/MM/yyyy h:mm:ss tt", CultureInfo.InvariantCulture); Demo Now, if you want to convert it to string with this format MM-dd-yyyy: string result = dt.ToString("MM-dd-yyyy", CultureInfo.InvariantCulture);

Categories : C#

Date Conversion with ThreadLocal
The idea behind this is that SimpleDateFormat is not thread-safe so in a mutil-threaded app you cannot share an instance of SimpleDateFormat between multiple threads. But since creation of SimpleDateFormat is an expensive operation we can use a ThreadLocal as workaround static ThreadLocal<SimpleDateFormat> format1 = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyy-MM-dd"); } }; public String formatDate(Date date) { return format1.get().format(date); }

Categories : Java

Special date conversion
Certainly in PostgreSQL you can add FM before the MM to remove any leading 0's: Running: select to_char(now(), 'yyyy/mm/dd'); Produces: 2013/08/07 Whereas running: select to_char(now(), 'yyyy/FMmm/dd'); Produces: 2013/8/07 And according to this the same should work in oracle.: http://www.techonthenet.com/oracle/functions/to_char.php So I would try: TO_CHAR(SYSDATE, 'FMMM/YYYY'); HTH

Categories : Oracle

MySQL date conversion error
The DATEPART function doesn't exist in MySQL. Try using DATE_FORMAT. For example: select DATE_FORMAT(pubdate,'%d/%m/%Y') adjusted for your needs of course.

Categories : Mysql

Date conversion from 29/08/2013 to milliseconds
It works the same with 29/08/2013 although the Date.parse just takes it as mm/dd/yyyy. So you need to do: var toParse:String = "08/29/2013"; var milliseconds:Number = Date.parse(toParse);

Categories : Actionscript

Error in php date format conversion
Use DateTime object, to get php understand in which format you passing date to it. $date = DateTime::createFromFormat('d/m/Y', '18/07/2013'); echo $date ->format('Y-m-d');

Categories : PHP

Date conversion but not with expected output
There's probably something wrong with myDate. Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH,15); cal.set(Calendar.MONTH,9); cal.set(Calendar.YEAR,2010); Date date = new Date(cal.getTimeInMillis()); String S = new SimpleDateFormat("yyyy:MM:dd").format(date); System.out.println(S); The console says: 2010:10:15 Which is correct. Please note that for some reason months start indexing at 0 (!), so it's 0-11 (january to december).

Categories : Java

MongoTemplate find by date conversion
I got this to work by reversing the lte and gte calls. I wrote a test to show it working: @Test public void shouldBeAbleToQueryBetweenTwoDates() throws Exception { // setup SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'"); MongoTemplate mongoTemplate = new MongoTemplate(new Mongo(), "TheDatabase"); DBCollection collection = mongoTemplate.getCollection("myObject"); // cleanup collection.drop(); // date that should match Date expectedDate = dateFormat.parse("2013-06-12T00:00:00Z"); collection.insert(new BasicDBObject("cd", expectedDate)); // date that should not match (it's last year) collection.insert(new BasicDBObject("cd", dateFormat.parse("2012-06-12T00:00:00Z"))); // create and execute the query final

Categories : Java

String to Date Conversion in Spring 4.0
There is no builtin of Date values by default in spring. Here you go : How to initialize a Java Date object in Spring xml configuration file?

Categories : Spring

NullReference Exception in date Conversion
That means that somewhere you are accessing a field, property or method on a reference-type variable that is null (or accessing .Value on Nullable<T> struct). We can't tell you where, but ex.StackTrace can, as can adding a break-point and stepping through the code near where it errors, looking at the variables etc for the rogue null (or the correct null with a missing null-check)

Categories : C#

Date timezone conversion socket.io
Javascript date object in different locale and timezone This answer looks good. Store all your dates as UTC and then translate to receivers time zone.

Categories : Node Js

Conversion from string "" to type 'Date' is not valid
You have not assigned anything to array elements 5 and 6. When you hit those elements in the loop, CDate will return the error you have described. Tip - instantiate your array like this instead. That way, the compiler will calculate the length for you and avoid bugs like this. 'set the value for text boxs to array Dim arr As String() = { lblmontotal.Text, lbltuestotal.Text, lblwedtotal.Text, lblthurstotal.Text, lblfridtotal.Text } UPDATE With regard to your second question, there are lots of ways of doing this, but the simplest is to convert the value directly to a TimeSpan, and don't bother with the DateTime variable at all.

Categories : Vb.Net

Preventing Implicit Date Conversion in JavaScript
Use multiple string substitutions to preserve the original string: var foo = "2013-10-01T09:00:00.000-04:00"; var bar = foo.substr(-6); var baz = foo.substr(11,2) var isoDate = new Date(foo).toISOString().replace("Z",bar).replace(/T../,"T"+baz); var hours = String(baz).concat(Number(baz) < 12 ? "PM" : "AM").replace(/^0/,"")

Categories : Javascript

Scriptella - Date format conversion not working
Formatting rules are applied to the variable name, therefore exactly the same variable name should be used for both format description and the expansion placeholder. In your cause, try using $dob instead of the column number.

Categories : Misc

Error Conversion String to Date WebService
I found the problem. I think is a bug on Weblogic12c1.1 when you perform a simple test with Webblogic ´s WebService Client , it puts a blank spaces into the tag like this: 1999-12-24T22:00:00 The solution is split the blank spaces: 1999-12-24T22:00:00

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.