Android日历更改时间更改日期到今天(Android calendar changing time changing date to today)
我正在使用
Calendar
,我可以设置日期并获取未来的日期。 假设我有一个DatePickerDialog
设置日期,例如15-09-2016 ,我有一个TimePickerDialog
设置小时,例如: 22 : 30我的问题是当我使用
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 oneDatePickerDialog
which sets date for example 15-09-2016 and I have oneTimePickerDialog
which sets hour for example : 22:30My problem is when I use
DatePickerDialog
and set date to : 15-09-2016 it's ok. But, then I useTimePickerDialog
and try to change time,Calendar's
date is changing to today (27-07-2016).But if I use
TimePickerDialog
firstly then useDatePickerDialog
there is no issue and I am able to set date : 15-09-2016 22:30I 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
最满意答案
- 找到您的存储库。 (选择你认为它在的文件夹,并运行
ls -a
。如果你看到.git
,你可能是在正确的地方。
- 如果您尚未启动存储库,请执行以下操作之一:
- 如果你有从存储库复制的所有文件,你需要做的只是
git init
。- 如果你什么都没有,运行
git clone <https://something/foo/bar.git> <folder you want the repository to be in>
。 如果您不指定文件夹,它会在当前文件夹中创建它。- 创建分支:您可以使用单个命令而不是您在问题中使用的两个命令:
git checkout -b <your branch name>
- 在文件中进行一些更改。
- 跟踪您的更改:
git add <changed file> [<another changed file> [...]]
请注意,更改的文件可以是文件夹。
- 如果你删除了一个文件,使用
git rm <file>
这样Git知道你删除了它。- 提交你的修改:
git commit -m "what you did"
- 如果你需要将你的修改推回到主分支,使用
git checkout master
和git merge <your branch name>
。 这会将新分支上的所有提交移动到原始分支。- 将更改推送到在线存储库:
git push
- 首次推送任何分支时,请使用它:
git push --set-upstream <https://something/foo/bar.git> <your branch name>
- 从现在开始,您可以使用
git pull
将在线分支的更改合并到本地。- 如果对应该在分支中的主服务器进行更改,请检查分支并使用
git rebase master
。对不起,如果我进入了太多细节!
- 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.- 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>
- Make some changes in the files.
- 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.- Commit your changes:
git commit -m "what you did"
- If you need to push your changes back to the main branch, use
git checkout master
andgit merge <your branch name>
. This will move all commits on your new branch to the original branch.- 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!
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
如何为User Github Pages使用除master之外的分支(How can I use a branch other than master for User Github Pages)[2022-01-20]
没有办法做到这一点,因为所需的分支名称被硬编码到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上创建远程分支(Create a remote branch on GitHub)[2024-01-03]
看起来github有一个简单的UI来创建分支。 我打开了分支下拉菜单,它提示我“查找或创建一个分支...”。 键入新分支的名称,然后单击出现的“创建”按钮。 要从github检索新的分支,请使用标准的git fetch命令。 我不知道这将有助于您的基础问题,因为底层数据被推送到服务器(提交对象)是一样的,无论它被推送到什么分支。 It looks like github has a simple UI for creating branches. I opened the branch drop-down ... -
需要帮助上传到github(Need help uploading to github)[2024-05-02]
您不应该使用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
。 如果您不指定文件夹,它会在当前文件夹中创建它。 创建分支:您可以使用单个命令而不是您在问题中使用 ... -
为什么我不能将node_modules文件上传到GitHub存储库中?(Why can not I upload the node_modules file into GitHub repository?)[2022-03-28]
因为.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 ...