首页 \ 问答 \ Android日历更改时间更改日期到今天(Android calendar changing time changing date to today)

Android日历更改时间更改日期到今天(Android calendar changing time changing date to today)

我正在使用Calendar ,我可以设置日期并获取未来的日期。 假设我有一个DatePickerDialog设置日期,例如15-09-2016 ,我有一个TimePickerDialog设置小时,例如: 2230

我的问题是当我使用DatePickerDialog并将日期设置为: 15-09-2016它没关系。 但是,然后我使用TimePickerDialog并尝试更改时间, Calendar's日期将更改为今天( 27-07-2016 )。

但是,如果我首先使用TimePickerDialog然后使用DatePickerDialog没有问题,我可以设置日期: 15-09-2016 22:30

我检查了Google和Stackoverflow,并在创建此问题时查看了建议的问题,但我没有看到任何内容。

我的DatePickerDialog

DatePickerDialog datePickerDialog=
   new DatePickerDialog(thisActivity, new DatePickerDialog.OnDateSetListener() {
       @Override
       public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
          mCalendarAlarm.set(Calendar.YEAR, year);
          mCalendarAlarm.set(Calendar.MONTH, monthOfYear);
          mCalendarAlarm.set(Calendar.DAY_OF_MONTH, dayOfMonth);
          SimpleDateFormat dateformat = new SimpleDateFormat("dd MMM yyyy kk:mm",Locale.getDefault());
          String datetime = dateformat.format(mCalendarAlarm.getTime());
          alarmDate.setText(datetime);
          }}, mCalendarAlarm.get(Calendar.YEAR), mCalendarAlarm.get(Calendar.MONTH),
          mCalendarAlarm.get(Calendar.DAY_OF_MONTH));

datePickerDialog.getDatePicker().setMinDate(mCalendarAlarm.getTimeInMillis());
datePickerDialog.show();

我的TimePickerDialog

TimePickerDialog mTimePicker;
int hour = mCalendarAlarm.get(Calendar.HOUR_OF_DAY);
int minute = mCalendarAlarm.get(Calendar.MINUTE); 
mTimePicker = new TimePickerDialog(thisActivity,mPickerTheme, new TimePickerDialog.OnTimeSetListener() {
   @Override
   public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
       mCalendarAlarm.set(Calendar.HOUR_OF_DAY,selectedHour);
       mCalendarAlarm.set(Calendar.MINUTE,selectedMinute);
       alarmDialogTime.setText(String.format(Locale.getDefault(),"%02d:%02d", selectedHour, selectedMinute));
       }}, hour, minute, true);
mTimePicker.show();

声明Calendar

mCalendarAlarm = Calendar.getInstance();
mCalendarAlarm.setTimeZone(TimeZone.getDefault());

那么我怎么能解决这个问题,或者你们之前有没有办法解决这个问题。 感谢帮助 !


I am using Calendar and I am able to set date and get date for future. Assume that I have one DatePickerDialog which sets date for example 15-09-2016 and I have one TimePickerDialog which sets hour for example : 22:30

My problem is when I use DatePickerDialog and set date to : 15-09-2016 it's ok. But, then I use TimePickerDialog and try to change time, Calendar's date is changing to today (27-07-2016).

But if I use TimePickerDialog firstly then use DatePickerDialog there is no issue and I am able to set date : 15-09-2016 22:30

I checked Google and Stackoverflow and looked suggested questions when creating this question but i didnt see anything.

My DatePickerDialog :

DatePickerDialog datePickerDialog=
   new DatePickerDialog(thisActivity, new DatePickerDialog.OnDateSetListener() {
       @Override
       public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
          mCalendarAlarm.set(Calendar.YEAR, year);
          mCalendarAlarm.set(Calendar.MONTH, monthOfYear);
          mCalendarAlarm.set(Calendar.DAY_OF_MONTH, dayOfMonth);
          SimpleDateFormat dateformat = new SimpleDateFormat("dd MMM yyyy kk:mm",Locale.getDefault());
          String datetime = dateformat.format(mCalendarAlarm.getTime());
          alarmDate.setText(datetime);
          }}, mCalendarAlarm.get(Calendar.YEAR), mCalendarAlarm.get(Calendar.MONTH),
          mCalendarAlarm.get(Calendar.DAY_OF_MONTH));

datePickerDialog.getDatePicker().setMinDate(mCalendarAlarm.getTimeInMillis());
datePickerDialog.show();

My TimePickerDialog :

TimePickerDialog mTimePicker;
int hour = mCalendarAlarm.get(Calendar.HOUR_OF_DAY);
int minute = mCalendarAlarm.get(Calendar.MINUTE); 
mTimePicker = new TimePickerDialog(thisActivity,mPickerTheme, new TimePickerDialog.OnTimeSetListener() {
   @Override
   public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
       mCalendarAlarm.set(Calendar.HOUR_OF_DAY,selectedHour);
       mCalendarAlarm.set(Calendar.MINUTE,selectedMinute);
       alarmDialogTime.setText(String.format(Locale.getDefault(),"%02d:%02d", selectedHour, selectedMinute));
       }}, hour, minute, true);
mTimePicker.show();

When declaring Calendar :

mCalendarAlarm = Calendar.getInstance();
mCalendarAlarm.setTimeZone(TimeZone.getDefault());

So how can I solve this issue , is there a way or you guys meet this issue before. Thanks for help !


原文:https://stackoverflow.com/questions/38622800
更新时间:2022-09-12 12:09

最满意答案

  1. 找到您的存储库。 (选择你认为它在的文件夹,并运行ls -a 。如果你看到.git ,你可能是在正确的地方。
    • 如果您尚未启动存储库,请执行以下操作之一:
      • 如果你有从存储库复制的所有文件,你需要做的只是git init
      • 如果你什么都没有,运行git clone <https://something/foo/bar.git> <folder you want the repository to be in> 。 如果您不指定文件夹,它会在当前文件夹中创建它。
  2. 创建分支:您可以使用单个命令而不是您在问题中使用的两个命令: git checkout -b <your branch name>
  3. 在文件中进行一些更改。
  4. 跟踪您的更改: git add <changed file> [<another changed file> [...]]请注意,更改的文件可以是文件夹。
    • 如果你删除了一个文件,使用git rm <file>这样Git知道你删除了它。
  5. 提交你的修改: git commit -m "what you did"
  6. 如果你需要将你的修改推回到主分支,使用git checkout mastergit merge <your branch name> 。 这会将新分支上的所有提交移动到原始分支。
  7. 将更改推送到在线存储库: git push
    • 首次推送任何分支时,请使用它: git push --set-upstream <https://something/foo/bar.git> <your branch name>
    • 从现在开始,您可以使用git pull将在线分支的更改合并到本地。
    • 如果对应该在分支中的主服务器进行更改,请检查分支并使用git rebase master

对不起,如果我进入了太多细节!


  1. Find your repository. (Pick the folder you think it's in, and run ls -a. If you see .git, you're probably in the right place.
    • If you do not have the repository initilized yet, do one of the following:
      • If you have all the files copied from the repository, all you need to do is git init.
      • If you have nothing, run git clone <https://something/foo/bar.git> <folder you want the repository to be in>. If you specify nothing for the folder, it will create it in the current folder.
  2. Create a branch: You can use a single command instead of the two commands you have in your question: git checkout -b <your branch name>
  3. Make some changes in the files.
  4. Track your changes: git add <changed file> [<another changed file> [...]] Note that a changed file can be a folder.
    • If you deleted a file, use git rm <file> so Git knows you deleted it.
  5. Commit your changes: git commit -m "what you did"
  6. If you need to push your changes back to the main branch, use git checkout master and git merge <your branch name>. This will move all commits on your new branch to the original branch.
  7. Push your changes to the online repository: git push
    • For your first time pushing any branch, use this instead: git push --set-upstream <https://something/foo/bar.git> <your branch name>
    • From now on, you can incorporate changes from the online branch to your local by using git pull.
    • If changes are made on master that should be in your branch, checkout your branch and use git rebase master.

Sorry if I went into too much detail!

相关问答

更多
  • 没有办法做到这一点,因为所需的分支名称被硬编码到Github的页面实现中。 您可以做的一件事是创建一个项目页面并将其视为用户页面,如果您设置自定义域 ,该页面的效果会更好。 一个简单的解决方法是创建一个具有不同名称的分支,并将其视为主分支。 它不会被命名为“master”,但最后每个分支看起来都和Git相同,所以它只是一个语义问题。 There is no way to do this, as the required branch names are hard-coded into Github's pa ...
  • 您的项目基本上包括源代码(由开发人员创建),管理配置文件(如bower.json,package.json等)。 所有这些文件都需要放在github上。 其他文件,如node_modules / ,bower_components / ,可以从互联网上下载,不应该放在github上。 您可以考虑这种情况,所有需要支持Web应用程序逻辑的文件都应该放在github上。 可以忽略可以下载的其他文件。 换句话说,您创建项目结构并初始化git存储库。 如果其他人将此存储库克隆到他们的计算机,应该需要哪些文件? Yo ...
  • 看起来github有一个简单的UI来创建分支。 我打开了分支下拉菜单,它提示我“查找或创建一个分支...”。 键入新分支的名称,然后单击出现的“创建”按钮。 要从github检索新的分支,请使用标准的git fetch命令。 我不知道这将有助于您的基础问题,因为底层数据被推送到服务器(提交对象)是一样的,无论它被推送到什么分支。 It looks like github has a simple UI for creating branches. I opened the branch drop-down ...
  • 您不应该使用git clone ,如果您这样做,您不能因为权限被拒绝而将更改推送到您的教师的回购。 尝试使用以下步骤: 单击教师的repo URL上的fork按钮,它将显示另一个页面,单击克隆或下载 ,复制https地址 在本地目录中,使用git clone ,这样您就可以对fork repo进行更改 使用git commit提交更改,并使用git push ,然后就可以成功推送 当您的老师登录他的Git ...
  • 你可以做到 git fetch REMOTE_NAME REMOTE_NAME是你如何调用遥控器的,如果你不知道这个机会就叫它origin 。 一旦你完成了,你应该这样做 git checkout second 从现在开始,分支就在您的本地存储库中。 You could do git fetch REMOTE_NAME where REMOTE_NAME is how you called the remote, if you don't know this chances are it's call ...
  • 找到您的存储库。 (选择你认为它在的文件夹,并运行ls -a 。如果你看到.git ,你可能是在正确的地方。 如果您尚未启动存储库,请执行以下操作之一: 如果你有从存储库复制的所有文件,你需要做的只是git init 。 如果你什么都没有,运行git clone 。 如果您不指定文件夹,它会在当前文件夹中创建它。 创建分支:您可以使用单个命令而不是您在问题中使用 ...
  • 因为.gitignore是在生成项目时生成的,并且它包含排除了被推送的node_modules存储库的行。 这样做是因为该文件夹可能非常沉重(几百Mb),并且会导致您的推送时间很长,而且不会与您的semver达成一致。 如果其他用户想要在本地运行您的项目,他们将不得不在运行之前运行npm i 。 这被广泛接受为标准。 所以我的建议是写一个有用的README给你的用户解释,而不是把你的node_modules文件夹推到你的仓库。 Because a .gitignore is generated when y ...
  • 这是因为文件名的大小写发生了变化。 git config core.ignorecase true修复了它 This happened due to a case change on the filename. git config core.ignorecase true fixed it
  • 一旦你在本地拥有repo并修改了你要修改的文件。 在存在.git目录中打开gitbash 执行 git add . git commit -m "Commit Message" git push origin master Once you have repo locally and you modiied file you want to modify. Open gitbash in directory where .git is present execute git add . git commit ...

相关文章

更多

最新问答

更多
  • 您如何使用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)