首页 \ 问答 \ 如何在POSIXct中获得一天的开始(How to get the beginning of the day in POSIXct)

如何在POSIXct中获得一天的开始(How to get the beginning of the day in POSIXct)

我的一天开始于2016-03-02 00:00:00 。 不是2016-03-02 00:00:01

我如何在当地时间在POSIXct中获得一天的开始?

我的困惑可能来自于R将此视为2016-03-01的结束日期的事实? 鉴于R使用ISO 8601?

例如,如果我尝试使用Sys.Date()来查找一天的开始:

as.POSIXct(Sys.Date(), tz = "CET")
"2016-03-01 01:00:00 CET"

哪个不正确 - 但还有其他方法吗?

我知道我可以用简单的方式破解我的出路

as.POSIXct(paste(Sys.Date(), "00:00:00", sep = " "), tz = "CET")

但是必须有更正确的方法来做到这一点? 基础R优先。


My day starts at 2016-03-02 00:00:00. Not 2016-03-02 00:00:01.

How do I get the beginning of the day in POSIXct in local time?

My confusing probably comes from the fact that R sees this as the end-date of 2016-03-01? Given that R uses an ISO 8601?

For example if I try to find the beginning of the day using Sys.Date():

as.POSIXct(Sys.Date(), tz = "CET")
"2016-03-01 01:00:00 CET"

Which is not correct - but are there other ways?

I know I can hack my way out using a simple

as.POSIXct(paste(Sys.Date(), "00:00:00", sep = " "), tz = "CET")

But there has to be a more correct way to do this? Base R preferred.


原文:https://stackoverflow.com/questions/35720154
更新时间:2021-04-11 20:04

最满意答案

$ .ajax方法的默认contentType是'application/x-www-form-urlencoded'

如果您想发送JSON,则必须指定您正在发送JSON,否则模型活页夹将无法正常工作:

$.ajax({
        type: 'post',
        url: "@Url.Action("SaveTireRunModel", "Events")",
        data: tirerun,
        contentType: 'application/json',
        success: function(result) {
            if (!result.success) {
                alert(result.error);
            } else {}
        }
    });

您可能还需要使用以下data: JSON.stringify(tirerun)对数据进行“ data: JSON.stringify(tirerun) ”: data: JSON.stringify(tirerun)


The default contentType for the $.ajax method is 'application/x-www-form-urlencoded'

If you want to send JSON you have to specify that your are sending JSON otherwise the Model Binder won't work correctly:

$.ajax({
        type: 'post',
        url: "@Url.Action("SaveTireRunModel", "Events")",
        data: tirerun,
        contentType: 'application/json',
        success: function(result) {
            if (!result.success) {
                alert(result.error);
            } else {}
        }
    });

You maybe also need to "stringify" the data with : data: JSON.stringify(tirerun)

相关问答

更多
  • 我建议按照以下方式构建它: 为每个页面创建一个具有特定KnockOut ViewModel的不同JavaScript模块: var app = app || {}; app.pages = app.pages || {}; app.pages.userProfile = (function () { function UserProfileViewModel() { //view model specific code }; function init() { ...
  • 相关文章

    更多

    最新问答

    更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)