我在 eclipse 下看到了这 3 个功能。我对它们有一个想法,但我不知道它们之间的确切区别。
它们都定义了某种类型的规则并应用了更改。例如:- 如果您有任何未使用的导入,您可以根据清理、格式化程序或检查样式的设置删除未使用的导入。checkstyle、格式化程序和清理之间有什么区别?
我正在尝试将其DateComponentsFormatter与新的 Foundation 格式化程序一起使用。要格式化日期,我可以这样做:
Date.now.formatted(.dateTime.hour().minute().second())
// 5:03:17 PM
Run Code Online (Sandbox Code Playgroud)
但是,我正在尝试使用这个新的 API 来使用DateComponentsFormatter:
let duration: TimeInterval = 0
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .positional
formatter.allowedUnits = [.minute, .second]
formatter.zeroFormattingBehavior = [.pad]
let formattedDuration = formatter.string(from: 0)
// 00:00
Run Code Online (Sandbox Code Playgroud)
如何使用新的 Foundation 格式化程序 API 来DateComponentsFormatter实现此目的?
duration formatter nsdatecomponents swift nsdatecomponentsformatter
我需要以一种它们应该以零开头的方式格式化数字以包含5位数.
我不知道如何为java格式化程序创建模式.
我试过%4d但它没有添加零.
我试图在jqGrid上格式化一个单元格,以便当用户编辑它时,它们会显示一个组合框的自定义实现(称为activecombo),因为select html组件很难看.
我已经阅读了这些并看了演示,但他们似乎没有做我想要的.这是我尝试过的:
var maritalStatusPickerFunction = function(cellvalue, options,
rowObject) {
var optionsArray = [ {
"id" : 1,
"status" : "Married"
}, {
"id" : 2,
"status" : "Divorced"
}, {
"id" : 3,
"status" : "Separated"
}, {
"id" : 4,
"status" : "Widowed"
}, {
"id" : 5,
"status" : "Unmarried"
}
];
var comboInput = $("<input type='text' value='" + cellvalue
+ "' />");
comboInput.activecombo( {
source : optionsArray
});
return comboInput;
};
$('#relationshipsGrid').jqGrid( {
datatype …Run Code Online (Sandbox Code Playgroud) 所以,我有以下代码写入文件:
Formatter output = ....... // Creating the formatter works, writes to appropriate file.
output.format("%d\n", records.length);
for(GradeRecord gR:records)
{
output.format(gR.toString() + "\n");
}
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,输出没有换行符.
如果我用"\ _"替换"\n"也不起作用.
......我不知道为什么这不起作用.输出已创建并正确写入.(我看到创建的文件,所有内容都写在其中,除了换行符.)
Clojure代码
(def fmt (java.text.SimpleDateFormat. "yyyy-MM-dd"))
#'user/fmt
user=> (.parse fmt "2015-07-10")
#inst "2015-07-09T22:00:00.000-00:00"
Run Code Online (Sandbox Code Playgroud)
类似的Java代码:
public class DateFmt {
public static void main(String[] args) throws ParseException {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
final Date date = sdf.parse("2015-07-10");
System.out.println(date);
}
}
Run Code Online (Sandbox Code Playgroud)
虽然Java代码打印:2015年7月10日00:00:00 CEST 2015(这是我的预期),但Clojure转移了2个小时?
我想为DetailView和GridView创建自己的格式选项.我现在使用可用的格式化程序选项,如datetime:
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'current_date:datetime'
]
]?>
Run Code Online (Sandbox Code Playgroud)
我想拥有这样的格式化程序:
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'current_date:datetime',
'colorId:color'
]
]?>
Run Code Online (Sandbox Code Playgroud)
其中color将colorId(即int的颜色标识符)转换为颜色名称.我知道我可以在模型中有一个函数/虚拟属性,但我想在任何地方使用它,而不仅仅是在某个模型上.我一直在搜索,但发现只需要我有特定的格式化程序.
Javascript:
function LinkFormatter(value, row, index) {
return "<a href='"+row.url+"'>"+value+"</a>";
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<th data-field="snum" data-sortable="true" data-formatter="LinkFormatter" >LINK</th>
<th data-sortable="true">DATA</th>
Run Code Online (Sandbox Code Playgroud)
JSON:
{
data: [
[
"https://www.stackoverflow.com",
"Stackoverflow"
]
]
}
Run Code Online (Sandbox Code Playgroud)
对于这种组合,我仅在表的第一列中获得一个条目,该条目表示未定义,并且还链接到/ undefined。但是,我只想显示一列Stackoverflow的列,它是Stackoverflow的URL。
我想念什么?
只要是关于Web API的新手。
网络Api:
[HttpGet]
public IHttpActionResult Test()
{
var doc = new XmlDocument();
XmlElement tournament = (XmlElement)doc.AppendChild(doc.CreateElement("Tournament"));
XmlElement match = (XmlElement)tournament.AppendChild(doc.CreateElement("Match"));
match.SetAttribute("ID", "SomeMatch");
return Ok(doc.InnerXml);
}
Run Code Online (Sandbox Code Playgroud)
结果:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><Tournament><Match ID="SomeMatch" /></Tournament></string>
两个问题:
以及如何取回
<Tournament>
<Match ID="SomeMatch" /></Tournament>
Run Code Online (Sandbox Code Playgroud) 给定这个 Rust 程序,它打印1.23456:
use std::fmt;
struct Foo(f64);
impl fmt::Display for Foo {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{}", self.0)
}
}
fn main() {
println!("{:.2}", Foo(1.23456));
}
Run Code Online (Sandbox Code Playgroud)
对函数体进行最简单的更改fmt以进行打印1.23?一般来说,是否有一种简单的方法可以在函数内部使用fmt打印对象的代码设置的相同格式选项?我知道格式化程序对象有几种访问格式化选项的方法,但是有没有一种简单的方法可以始终获得通过调用获得的相同结果println!("{:.2}", Foo(1.23456).0);?