I have these time formats in Java which I use to format the date:
dd-mm-yyyy
dd-mm-rr
dd-mon-yyyy
dd-mon-rr
dd/mon/yyyy
When I use these time formats with JQuery time picker I get this output:
24-08-rr
24-08-20122012
Can you tell me how I can use one time format for Java and for JavaScript? How I can solve this problem?
For example you can use next:
-On client side
$("#input-field-id").datepicker().mask("99/99/9999");
-On server side
org.joda.time.format.DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormat.forPattern("MM/dd/yyyy");
DATE_TIME_FORMATTER.parseDateTime(dateThatYouGatFromClientPart);
You can use latest version of jQuery UI datepicker which has the following useful functions
http://docs.jquery.com/UI/Datepicker/formatDate
http://docs.jquery.com/UI/Datepicker/parseDate
Related
I want to generate date in the format 2019-03-28T15:30:59+12:00 using wiremock.
I tried:
"currentDateTime": "{{now timezone='Australia/Sydney' format='yyyy-MM-dd'T'HH:mm:ssZ'}}"
but, I get exception:
wiremock.com.github.jknack.handlebars.HandlebarsException: inline:
found: ''yyyy-MM-dd'T'HH:mm:ssZ'', expected: 'no viable alternative at
input ''yyyy-MM-dd'T'HH:mm:ssZ'''
I have also tried escaping both the quotes around T, but it does not work.
What I am doing wrong?
Try using following block of code. Working fine for me and probably the best way.
format='yyyy-MM-dd\'T\'HH:mm:ss.SSSXXX'
In case anyone else comes across this post in the future, the simplest (but hacky) solution that I used is to format the parts before and after the 'T' separately like so:
"currentDateTime": "{{now timezone='Australia/Sydney' format='yyyy-MM-dd'}}T{{now timezone='Australia/Sydney' format='HH:mm:ssZ'}}"
A simple workaround:
Declare a variable (myformat in the example)
{{#assign 'myformat'}}yyyy-MM-dd'T'HH:mm:ssZ{{/assign}}
Use it in the stub/mock
{{now format=myformat}}
A sample templated response is -
{
"time": "{{#assign 'myformat'}}yyyy-MM-dd'T'HH:mm:ssZ{{/assign}}{{now format=myformat}}"
}
References
How to use custom variables in Handlebars for WireMock
https://wiremock.org/studio/docs/response-templating/misc-helpers/#assignment
If you need to include the date in the ISO 8601 format, you can omit the format option:
{{now timezone='Australia/Sydney'}}
It will produce the following result: 2021-06-09T05:45:53+10:00. If you omit the timezone and just use {{now}} - it will produce a date in UTC: 2021-06-08T19:48:27Z.
For reference, you can check the RenderableDate class in wiremock
"body": "{\"datetime\": \"{{now format='yyyy-MM-dd\\'T\\'HH:mm:ss'}}\"}"
I would like to ask how can i get string with 'now' date in the following format?
"2015-10-08T08:09:22.067+00:00" ?
Many thanks for any advice.
Have a look here at the simpledateformat method:
http://developer.android.com/reference/java/text/SimpleDateFormat.html
I think you should use the simple date format to format your date string . For this, consider reading the this link .
But if you want just to change the string and get the time then just follow this link or this link
I hope this answer would help you.
I am developing one Java application and getting data from webservice with parameter Time "HH:mm:ss.000Z" format.
How do I convert Time "HH:mm:ss.000Z" from Time "HH:mm:ss" format using below line but getting same error for time.
There is auto generated code from wsdl.
org.apache.axis.types.Time time=new org.apache.axis.types.Time("00:00:01");
Check implementation of class Time.
private static SimpleDateFormat zulu =
new SimpleDateFormat("HH:mm:ss.SSS'Z'");
This is SimpleDateFormat used by Time class to convert time to that format.
I'm trying to format a date for a given locale new Locale("mk", "MK"). The locale is valid, it returns the country name and language properly. I want to use custom string, in my case "E, kk:mm" or "EEEE, kk:mm". I want the output to be "сабота, 12:00", but what I get is "7, 12:00".
This is how I use it and I tried many ways, but they all seem to behave the same.
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, kk:mm", new Locale("mk", "MK));
sdf.format(new Date());
// output: 7, 12:30
Another method I tried
Calendar calendar = Calendar.getInstance(new Locale("mk", "MK"));
calendar.setTimeInMillis(new Date().getTime());
DateFormat.format("EEEE, kk:mm", calendar);
// output: Saturday, 12:30
I also tried using java.text.DateFormat instead android class, but no change.
The phone locale is set to English, but this is localized app, I want to show dates in a fixed locale format.
I've looked into many SO question regarding this issue and I wasn't able to find answer. I'm not interested in predefined formats, I want to use my own format and I want the date/month names to be formatted for the input locale.
I think the problem is that Macedonia is not a supported locale on the Android JVM. If you run your code as plain Java console app, it's fine. The method Locale.getAvailableLocales() returns 152 members in plain Java, only 88 in an Android emulator. If you have the code snippet:
Locale[] locales = Locale.getAvailableLocales();
String cCode;
for (Locale loc :locales){
cCode = loc.getCountry();
if (cCode.equalsIgnoreCase("MK"))
Toast.makeText(this, cCode, Toast.LENGTH_SHORT).show();
// Or System.out.println() in a Java app
}
Then the toast doesn't show for "MK" although it will println in the Java app
From documentation of SimpleDateFormat:
**Text**: For formatting, if the number of pattern letters is 4 or more,
the full form is used; otherwise a short or abbreviated form is used if
available. For parsing, both forms are accepted, independent of the
number of pattern letters.
So this should fix it:
SimpleDateFormat sdf = new SimpleDateFormat("EEEE, kk:mm", new Locale("mk", "MK"));
NickT was faster :-), so just adding to his answer: if you want to see your locales supported on Android, run:
for (Locale l:Locale.getAvailableLocales()) {
Log.d(l.getDisplayCountry(),l.toString());
}
and you will see that Macedonia is not on the list.
How do I format time using Android's Time Class.
I want to display time in this format "hh:mm AM/PM" . I have tried using the Time.format function but I'm not sure if I'm using it correctly.
Thanks
Please try this..
SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aa");
Date dt = new Date();
String strValue = timeFormat.format(dt);
Time time = new Time();
time.set(0, 0, 17, 4, 5, 1999);
Log.i("Time", time.format("%d.%m.%Y %H:%M:%S"));
try:
String strTime = time.format("%I:%M %p");
Your answer can be derived from, but not limited to this link, a C++ reference about "ctime":
http://www.cplusplus.com/reference/ctime/strftime/
I found this link to be very helpful deciphering the string formats used in my own work.
The Android.Text.Format.Time.Format docs assumes you know something:
Where or how to read "man" page for strftime, which if you weren't familiar using Linux (or a Mac at the terminal) might require some creative web searching or know what "See man strftime for what means what." referred to. Informal as it is in official documentation, it does build off and reference what has already has come before and is left as an exercise for the developer.