How to format date in flex? - java

I'm using Flex+java+Mysql.. in that i want to insert the datetime taking from flex to mysql in that i got date String like this
Sat Aug 4 12:05:00 GMT+0530 2012
how to convert yyyy-MM-dd HH:mm:ss z
this formate so please give code in java or flex...

In flex API Given DateFile class, in that we have two methods dateTOString(), stringTODate().
DateField.dateToString(dateInput.selectedDate,"DD-MM-YYYY");
Please Refere Below Doc.
DateField

DateField.dateToString(addr1.selectedDate,"YYYY-MM-DD").toString();

Related

SimpleDateFormat returns "Sun Oct 10 00:00:00 BRT 2010" but insert "2010-10-10"

i have a code where i use a SimpleDateFormat:
String data = jTData.getText();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date dataInserir = null;
dataInserir = formatter.parse(data);
System.out.println(dataInserir);
The output for this code if the string from the jTData.getText()is "2010-10-10" is:
Sun Oct 10 00:00:00 BRT 2010.
But, it is inserted in the database the value 2010-10-10.
The field is:
#Temporal(javax.persistence.TemporalType.DATE)
private Date data;
What am i missing that i'm not able to get an output like 2010-10-10 as a Date ?
And why is this inserting the value 2010-10-10 if the output is Sun Oct 10 00:00:00 BRT 2010?
Any help i'll be grateful, thanks.
I suspect you are confusing the nature of the java.util.Date class versus java.sql.Date. The first is a date and time-of-day, the second is date-only.
You marked marked your annotation as javax.persistence.TemporalType.DATE. The doc for that enum says simply:
Map as java.sql.Date
You said to store a date-only.
So what you are experiencing is a feature, not a bug.
If you want to store a date with a time-of-day, use the javax.persistence.TemporalType.TIMESTAMP annotation.
Back that with a timestamp type on the column in your database (should almost always be a timestamp-with-time-zone type).
Also, I recommend using the java.time framework rather than the troublesome java.util.Date and SimpleDateFormat classes. But that is a whole other topic.

How to set date format in sybase?

How to set date format in sybase?
Currently it's inserting default date format Jan 9 2014 1:07AM to Sybase DB,But i have to insert seconds also like "20140109 01:06:46"
Is there any way i can set date format in stored proc.
please suggest me,thanks!
select --cast(
dateformat('Jan 9 2014 1:07AM','YYYYMMDD HH:NN:SS') --returns varchar
--as datetime) --datetime object in database datetime format

how to convert java date string to date in vbscript with lacale

I have to convert a java string to date in vbscript with given locale. below are some of date string
Dim dstr,dstr2
dstr= 30 Oct 2013 07:49:37 GMT
dstr2 =30-Oct-2013 13:20:22 India Standard Time
From these if I remove there locale then below syntax work
CDate(replace(dstr,"GMT"),"")
CDate(replace(dstr,"India Standard Time"),"")
But it does not give Locale. can any body tell me how can I fetch date with local given in the string.
I'm not sure whether I got your question correctly or not but here goes:
Dim dstr, dstr2, intRegionalCode
intRegionalCode = GetLocale()
dstr = "30 Oct 2013 07:49:37 GMT"
dstr2 = "30-Oct-2013 13:20:22 India Standard Time"
SetLocale("en-gb")
MsgBox CDate(replace(dstr,"GMT",""))
MsgBox CDate(replace(dstr2,"India Standard Time",""))
SetLocale("en-us")
MsgBox CDate(replace(dstr,"GMT",""))
MsgBox CDate(replace(dstr2,"India Standard Time",""))
SetLocale(intRegionalCode)
I hope this helps.
For more information you can check here.
GetLocale help

Google DateTime Class - Date Formatting In Java

So I'm using the google blogger.com api and I have a blog post date in Google's Date Time class format.....
http://code.google.com/apis/gdata/javadoc/com/google/gdata/data/DateTime.html
What is the easiest way in Java to format that DateTime object to display in this format?
Mar 1, 2012 12:45 PM
use the SimpleDateFormat class for format the any date format

how to convert from 10/21/2009 to Wed Oct 21 18:48:12 UTC+0530 2009

hi can any one please help me on how to convert from 10/21/2009 to Wed Oct 21 18:48:12 UTC+0530 2009 in my java class
Quite frankly, you can't convert 10/21/2009 to Wed Oct 21 18:48:12 UTC+0530 for the simple reason that the first date does contain neither time nor timezone information.
String dateString = new SimpleDateFormat("dd/MM/yyyy").parse(d).toString();
Here you'll get more information: https://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html.
You don't specify if the original value (10/21/2009) is a date object or a string, I'm going to assume that it is in fact a String, so you first need to parse the string and convert it to a date object using the SimpleDateFormatter class
import java.text.SimpleDateFormatter;
SimpleDateFormatter sdf = new SimpleDateFormatter("MM/dd/yyyy");
Date d = sdf.parse("10/21/2009");
Once you have a date object, you can just call toString() on it which will get you the string you want, or create another SimpleDateFormatter object with the pattern that you want (check the javadocs) and then call format().
There's a couple of things you should be aware of regarding the DateFormatter classes available in the JDK
If the string can not be parsed, the parse method will throw an exception, you will need to handle the exception accordingly
The date formatter classes available in the JDK are not threadsafe. Don't create a private/protected/public member variable of these types, instead create the formatters/parsers in the methods where you need them

Categories