format

Java format hour and min

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-10 04:28:11
问题 I need to format my time string such as this: int time = 160; Here's my sample code: public static String formatDuration(String minute) { String formattedMinute = null; SimpleDateFormat sdf = new SimpleDateFormat("mm"); try { Date dt = sdf.parse(minute); sdf = new SimpleDateFormat("HH mm"); formattedMinute = sdf.format(dt); } catch (ParseException e) { e.printStackTrace(); } return formattedMinute; // int minutes = 120; // int h = minutes / 60 + Integer.parseInt(minute); // int m = minutes %

PHP - Force integer conversion to float with three decimals

不想你离开。 提交于 2020-01-10 04:28:05
问题 I am trying to convert a big array of numbers to a specific format which is +/-NNN.NNN. So, if I have these numbers: $numbers1 = array(-1.23, 0.3222, 10, 5.54); I want their final format to be $numbers2 = array(-001.023, +000.322, +010.000, +005.054); I am trying to do it like this: foreach ($numbers1 as $n) { $fnum = abs(number_format((float)$n, 3, '.', '')); if ($fnum>0 && $fnum<10) { $fnum = '00'.$fnum; } else if ($fnum >= 10 && $fnum<100) { $fnum = '0'.$fnum; } if ($n>0) $fnum = '+'.$fnum

MySQL select rows with date like

风流意气都作罢 提交于 2020-01-10 02:29:11
问题 In MySQL I have this query SELECT DISTINCT date, descr FROM book ORDER BY date Date is in format yyyy-mm-dd I want to select only the the books from January 2012 . I have tried to use like but that does not work. Any ideas? 回答1: Using DATE_FORMAT function SELECT DISTINCT date, descr FROM book WHERE DATE_FORMAT(date, '%Y %m') = DATE_FORMAT('2012-01-01', '%Y %m') ORDER BY date Or using MONTH and YEAR functions SELECT DISTINCT date, descr FROM book WHERE Month(date) = Month('2012-01-01') AND

JavaScript datetime parsing [duplicate]

别来无恙 提交于 2020-01-10 01:43:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How can I convert string to datetime with format specification in JavaScript? I have a json response which contains a hashmap like; {"map":{"2012-10-10 03:47:00.0":23.400000000000002,"2012-10-10 03:52:00.0":23.3,"2012-10-10 03:57:00.0":23.3,"2012-10-10 04:02:00.0":23.3,"2012-10-10 04:07:00.0":23.200000000000003,"2012-10-10 04:13:00.0":23.1,"2012-10-10 04:18:00.0":23.1,"2012-10-10 04:23:00.0":23.0,"2012-10-10 04

Print Integer with 2 decimal places in Java

不打扰是莪最后的温柔 提交于 2020-01-10 01:02:48
问题 in my code i use integers multiplied by 100 as decimals (0.1 is 10 etc). Can you help me to format output to show it as decimal? 回答1: int x = 100; DecimalFormat df = new DecimalFormat("#.00"); // Set your desired format here. System.out.println(df.format(x/100.0)); 回答2: I would say to use 0.00 as format: int myNumber = 10; DecimalFormat format = new DecimalFormat("0.00"); System.out.println(format.format(myNumber)); It will print like: 10.00 The advantage here is: If you do like: double

Python dateutil.parser.parse parses month first, not day

故事扮演 提交于 2020-01-09 19:45:50
问题 I'm using dateutil.parser.parse to format a date from a string. But now it mixes up the month and the day. I have a string that contains 05.01.2015 . After dateutil.parser.parse("05.01.2015") it returns: datetime.datetime(2015, 5, 1, 0, 0) I hoped the it would return (2015, 1, 5, 0, 0) How can I tell the code that the format is dd.mm.yyyy ? For the record, 25.01.2015 will be parsed as (2015, 1, 25, 0, 0) , as expected. 回答1: Specify dayfirst=True : >>> dateutil.parser.parse("05.01.2015",

Reshape Data Long to Wide - understanding reshape parameters

久未见 提交于 2020-01-09 05:32:25
问题 I have a long format dataframe dogs that I'm trying to reformat to wide using the reshape() function. It currently looks like so: dogid month year trainingtype home school timeincomp 12345 1 2014 1 1 1 340 12345 2 2014 1 1 1 360 31323 12 2015 2 7 3 440 31323 1 2014 1 7 3 500 31323 2 2014 1 7 3 520 The dogid column is a bunch of ids, one for each dog. The month column varies for 1 to 12 for the 12 months, and year from 2014 to 2015. Trainingtype varies for 1 to 2. Each dog has a timeincomp

Using Struts2 Tags to Formatting Numbers

僤鯓⒐⒋嵵緔 提交于 2020-01-09 05:25:09
问题 I want to format some numbers in our jsp pages. first i define some resources in my porperties format.number.with2Decimal={0,number,#0.00} ...... Question1: i want to know what is the ‘#’ and '0' means? 0.00,#0.00,##.00,###0.00 who can tell me the differences between them? thanks! Question2: if i define a BigDecimal type in my action BigDecimal number1; Then my page should using a format to show this value, 1.if number1=null then show -NIL- 2.if number1=0 then show -NIL- 3.if number1>0 then

How to convert seconds to time format? [duplicate]

北慕城南 提交于 2020-01-09 01:59:09
问题 This question already has answers here : Convert seconds to Hour:Minute:Second (24 answers) Closed 6 years ago . For some reason I convert a time format like: 03:30 to seconds 3*3600 + 30*60, now . I wanna convert it back to its first (same) format up there. How could that be? My attempt: 3*3600 + 30*60 = 12600 12600 / 60 = 210 / 60 = 3.5, floor(3.5) = 3 = hour Now, what about the minutes? Considering the value can be like 19:00 or 02:51. I think you got the picture. And by the way, how to

Date format in jsp

試著忘記壹切 提交于 2020-01-07 09:03:34
问题 I need to convert the date from request parameter to string in dateformat 'yyyy-MM-dd'. I have tried the following String MyDate = request.getParameter("DayCal"); formatdate = new java.text.SimpleDateFormat("yyyy/MM/dd"); Date date = (Date) formatdate.parse(MyDate); String DisplayDate= formatdate.format(date); But i am getting incorrect results if the request.getParameter("DayCal") = 01/01/2010; the DisplayDate = 0006/07/03 Please help... Thanks in advance 回答1: You will need two