我正在寻找一年中第一天的DateTime修改字符串(现在是2011年1月1日).我尝试了以下方法:
<?php
$time = new DateTime();
// works as expected, the first day of the current month
$time->modify('first day of this month');
echo $time->format('c')."\n";
// this doesn't work. I also tried several other ways
$time->modify('first day of january');
echo $time->format('c')."\n";
>
Run Code Online (Sandbox Code Playgroud)
我知道有其他方法可以检索日期,但我搜索字符串的DateTime-> modify()没有其他解决方案.
出于测试目的,我需要一个这样的函数:
/**
* @param int $sizeInBytes
*
* @returns string with random data
*/
function randomData($sizeInBytes)
{
...
}
Run Code Online (Sandbox Code Playgroud)
任何有效实施的想法?需要速度但不是真正的随机性(更像是一种"lorem ipsum").我最简单的想法是在文件系统中使用真正的大文件并通过流获取所需的大小.但这需要至少100MB的文件.有没有更好的办法?
我有一个类,它基本上是 HashMap 的包装器。我想用 Jackson 将此类序列化为 JSON 对象,而不需要任何包装元素。
public class Customers {
@JsonProperty
private Map<String,Customer> customers = new HashMap<>();
...
}
Run Code Online (Sandbox Code Playgroud)
当前的序列化如下所示:
{
"Customers":{
"customers":{
"keyX":{...},
"keyY":{...},
"keyZ":{...}
}
Run Code Online (Sandbox Code Playgroud)
但我想要这个:
{
"keyX":{...},
"keyY":{...},
"keyZ":{...}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能达到它?
瞬态关键字到底意味着什么?我有一个标记为瞬态的Class属性:
public class NodeClassifier {
private transient HashMap<String, Node> nodeCache = new HashMap<>();
...
}
Run Code Online (Sandbox Code Playgroud)
在将NodeClassifier对象存储并恢复到HttpSession之后,属性仍具有上一个Session的值.
它不应该是空的吗?
Environment是一个在Glassfish4上运行的普通Servlet.