嗨,我正在尝试使用具有当前星期,月份和日期数组的javscript日期构建数组,例如,结构看起来如下;
EventData
我现在有以下代码;
public class TranslateEndpoint {
/**
* This function will be invoked when an event is received from Event Hub.
*/
@FunctionName("TranslateEndpoint")
public void run(
@BindingName("SystemProperties") Map<String, Object> systemProperties,
@EventHubTrigger(name = "message", eventHubName = "NAME-DeviceIntegration", connection = "HostName=HOST;SharedAccessKeyName=NAME;SharedAccessKey=KEY=", consumerGroup = "$Default", cardinality = Cardinality.ONE) String message,
final ExecutionContext context
) {
String deviceId = (String) systemProperties.get("iothub-connection-device-id");
//decode/parse message string
//...
}
}
但是我不确定如何通过星期数获取日期,任何想法如何实现?
答案 0 :(得分:0)
使用moment解析JavaScript中的日期方法
var weeknumber = moment(new Date()).week();
因此,如果您在获取正确的星期数方面遇到问题,请使用.isoWeek()
var weeknumber = moment(new Date()).isoWeek();
所以在您的情况下:
dateArray.push({
"week_number": moment(currentDate).week(),
"month": moment(currentDate).format("MMM"),
"year": moment(currentDate).year(),
...
})
谢谢:)