Format
I'd like to use the time command in a bash script to calculate the elapsed time of the script and write that to a log file. I only need the real time, not the user and sys. Also need it in a decent format. e.g 00:00:00:00 (not like the standard output). I appreciate any advice.
Source: (StackOverflow)
How do you format correctly according to the device configuration a date and time when having year, month, day, hour and minute?
Source: (StackOverflow)
How to parse the Date string below to Date object???
String target = "Thu Sep 28 20:29:30 JST 2000";
DateFormat df = new SimpleDateFormat("E MM dd kk:mm:ss z yyyy");
Date result = df.parse(target);
Throws exception...
java.text.ParseException: Unparseable date: "Thu Sep 28 20:29:30 JST 2000"
at java.text.DateFormat.parse(DateFormat.java:337)
Source: (StackOverflow)
Is there a simple way to convert one date format into another date format in PHP?
I have this:
$old_date = date('y-m-d-h-i-s'); // works
$middle = strtotime($old_date); // returns bool(false)
$new_date = date('Y-m-d H:i:s', $middle); // returns 1970-01-01 00:00:00
But I'd of course like it to return a current date rather than the crack 'o dawn. What am I doing wrong?
Source: (StackOverflow)
I'm trying to generate a JSON response that includes some HTML. Thus, I have /app/views/foo/bar.json.erb
:
{
someKey: 'some value',
someHTML: "<%= h render(:partial => '/foo/baz') -%>"
}
I want it to render /app/views/foo/_baz.html.erb
, but it will only render /app/views/foo/_baz.json.erb
. Passing :format => 'html'
doesn't help.
Source: (StackOverflow)
Here is the String, for example:
"Apple"
and I would like to add zero to fill in 8 chars:
"000Apple"
How can I do so?
Source: (StackOverflow)
x = " \{ Hello \} {0} "
print x.format(42)
gives me : Key Error: Hello\\
I want to print the output: {Hello} 42
Source: (StackOverflow)
I am trying to use a .format
method of a string. But if I place %1, %2, etc. in the string, java.util.UnknownFormatConversionException is thrown pointing to a confusing Java source code piece:
private void checkText(String s) {
int idx;
// If there are any '%' in the given string, we got a bad format
// specifier.
if ((idx = s.indexOf('%')) != -1) {
char c = (idx > s.length() - 2 ? '%' : s.charAt(idx + 1));
throw new UnknownFormatConversionException(String.valueOf(c));
}
}
From this I understand that %
char is forbidden. If so, then what should I use for argument placeholders?
I use Scala 2.8.
Source: (StackOverflow)
I want have a variable which contains the value 1234567.
I want it to contain exactly 8 digits i.e. 01234567.
Is there a PHP function for that?
Source: (StackOverflow)
How do you get the text of a TextView
to be Justified (with text flush on the left- and right- hand sides)?
I found a possible solution here, but it does not work (even if you change vertical-center to center_vertical, etc).
Source: (StackOverflow)
An 64-bit double can represent integer +/- 253 exactly
Given this fact I choose to use a double type as a single type for all my types, since my largest integer is unsigned 32-bit.
But now I have to print these pseudo integers, but the problem is they are also mixed in with actual doubles.
So how do I print these doubles nicely in Java?
I have tried String.format("%f", value)
, which is close, except I get a lot of trailing zeros for small values.
Here's an example output of of %f
232.00000000
0.18000000000
1237875192.0
4.5800000000
0.00000000
1.23450000
What I want is:
232
0.18
1237875192
4.58
0
1.2345
Sure I can write a function to trim those zeros, but that's lot of performance loss due to String manipulation. Can I do better with another format code?
EDIT
The answers by Tom E. and Jeremy S. are unacceptable as they both arbitrarily rounds to 2 decimal places. Please understand the problem before answering.
EDIT 2
Please note that String.format(format, args...)
is locale-dependent (see answers below).
Source: (StackOverflow)
I'm a Python newbie (2 weeks) and I'm having trouble formatting a datetime.timedelta
object.
Here's what I'm trying to do:
I have a list of objects and one of the members of the class of the object is a timedelta object that shows the duration of an event. I would like to display that duration in the format of hours:minutes.
I have tried a variety of methods for doing this and I'm having difficulty. My current approach is to add methods to the class for my objects that return hours and minutes. I can get the hours by dividing the timedelta.seconds by 3600 and rounding it. I'm having trouble with getting the remainder seconds and converting that to minutes.
By the way, I'm using Google AppEngine
with Django Templates
for presentation.
If anyone can help or knows of a better way to resolve this, I would be very happy.
Thanks,
Source: (StackOverflow)