string-formatting

The correct Javascript Date.parse(…) format string?

断了今生、忘了曾经 提交于 2020-01-21 00:59:25
问题 What is a culture-invariant way of constructing a string such that the Javascript Date() constructor can parse it and create the proper date object? I have tried these format strings which don't work (using C# to generate the strings): clientDate.ToString(); // gives: "11/05/2009 17:35:23 +00:00" clientDate.ToString("MMM' 'dd', 'yyyy' 'h':'mm':'ss' 'tt"); // works on an English server // but on a French server, gives: "mai 11, 2009 5:35:23" // Javascript won't parse that. clientDate.ToString(

The correct Javascript Date.parse(…) format string?

大憨熊 提交于 2020-01-21 00:59:06
问题 What is a culture-invariant way of constructing a string such that the Javascript Date() constructor can parse it and create the proper date object? I have tried these format strings which don't work (using C# to generate the strings): clientDate.ToString(); // gives: "11/05/2009 17:35:23 +00:00" clientDate.ToString("MMM' 'dd', 'yyyy' 'h':'mm':'ss' 'tt"); // works on an English server // but on a French server, gives: "mai 11, 2009 5:35:23" // Javascript won't parse that. clientDate.ToString(

How to produce “human readable” strings to represent a TimeSpan

无人久伴 提交于 2020-01-20 02:34:05
问题 I have a TimeSpan representing the amount of time a client has been connected to my server. I want to display that TimeSpan to the user. But I don't want to be overly verbose to displaying that information (ex: 2hr 3min 32.2345sec = too detailed!) For example: If the connection time is... > 0 seconds and < 1 minute -----> 0 Seconds > 1 minute and < 1 hour -----> 0 Minutes, 0 Seconds > 1 hour and < 1 day -----> 0 Hours, 0 Minutes > 1 day -----> 0 Days, 0 Hours And of course, in cases where the

Why does my Perl one-liner report “Bareword found where operator expected”?

天大地大妈咪最大 提交于 2020-01-17 06:08:47
问题 I want to convert block size into MB. I am using the /e option in my substitution. When I add starting MB in substitution part it giving me the error. e.g: This works. echo "16777216 SELECT" |perl -lane 's#(\d+)(\s+SELECT)#$1/(1024*1024*2)#e; print' 8 This giving me the error. echo "16777216 SELECT" |perl -lane 's#(\d+)(\s+SELECT)#$1/(1024*1024*2) MB $2#e; print' Bareword found where operator expected at -e line 1, near ") MB" (Missing operator before MB?) syntax error at -e line 1, near ")

Can a character style be applied programmatically to a string before it is written to the Word document with VBA?

青春壹個敷衍的年華 提交于 2020-01-16 16:57:23
问题 I am grabbing some data from an Excel sheet and populating it into a Word template. I'm hoping that I can assign some of the Document's character styles to sub strings that will be added to the Document as the string is built up rather than having add the string to the Document and then select each string individually to apply the appropriate style. Right now, I'm concatenating a few strings and adding them to a text box in the document like this: ActiveDocument.Shapes("Text Box 7").TextFrame

Is there a PHP function to format a currency amount in accounting format?

拈花ヽ惹草 提交于 2020-01-15 07:11:57
问题 I'm currently writing a report in PHP that occasionally has to display negative currency amounts. Said currency amounts are stored in the database like "-44.00". Ideally this number would be output as "($44.00)" on the report. I know I can write some semi-complicated function to detect whether the number is negative and manually insert the parenthesis, but I was wondering if there was some handy PHP function that can do this for me before I re-invent the wheel. I've searched around and have

Populating multiple printf format placeholders with same value

淺唱寂寞╮ 提交于 2020-01-14 18:48:11
问题 Using .NET string formatting you can plug the same value into a format string multiple times: Console.Write("{0}{0}{0}", 1) //prints "111" Is there any way to do this with printf-style formatting, supplying the value only once? 回答1: No. The values are taken in order, from the stack, when passed to the function. If you want multiple appearances of the same value if different parts of the string, you have to supply them in order, multiple times. Think of it this way: you have a string, with

Populating multiple printf format placeholders with same value

强颜欢笑 提交于 2020-01-14 18:45:32
问题 Using .NET string formatting you can plug the same value into a format string multiple times: Console.Write("{0}{0}{0}", 1) //prints "111" Is there any way to do this with printf-style formatting, supplying the value only once? 回答1: No. The values are taken in order, from the stack, when passed to the function. If you want multiple appearances of the same value if different parts of the string, you have to supply them in order, multiple times. Think of it this way: you have a string, with

how to set binding stringformat to all DataGridTextColumn controls?

筅森魡賤 提交于 2020-01-14 15:56:30
问题 This is one of my DataGridTextColumn controls looks like : <DataGridTextColumn x:Name="contractStartDateColumn" Header="Start Date" Binding="{Binding Path=StartDate, StringFormat={}\{0:dd/MM/yyyy\}}" /> Then how can I set StringFormat={}{0:dd/MM/yyyy} to all of DataGridTextColumn controls instead of setting every single one ? 回答1: You can create custom binding class that sets StringFormat and use it to bind values: public class CustomBinding : Binding { public CustomBinding(string path) :

Show Currency Symbol after values

心不动则不痛 提交于 2020-01-14 09:41:29
问题 I am using CultureInfo methods to successfully format all different currencies into their correct format. But on some exceptions, such as EUR and SEK currencies I need to be able to add them after the value. At the moment my CultureInfo is formatting them in the following way: "SEK 1.00,00" when it needs to be "1.00,00 SEK". Any help is appreciated. 回答1: All you need is to change the NumberFormatInfo.CurrencyPositivePattern and NumberFormatInfo.CurrencyNegativePattern properties for the