I have made a project to keep the record of temperature and time but while printing the records the time is not shown in proper way as in 24 hr format.
what i get is this:
8/4/2015 15:57:09 24.9
8/4/2015 15:57:39 25.39
8/4/2015 15:58:09 25.39
8/4/2015 15:58:39 23.44
8/4/2015 15:59:09 24.9
8/4/2015 15:59:39 25.39
8/4/2015 10:00:09 24.9
8/4/2015 10:00:39 25.39
8/4/2015 10:01:09 25.39
8/4/2015 10:01:39 25.39
8/4/2015 10:02:09 25.39
8/4/2015 10:02:39 25.39
but i wanted it to be:
8/4/2015 15:59:09 24.9
8/4/2015 15:59:39 25.39
8/4/2015 16:00:09 24.9
8/4/2015 16:00:39 25.39
Is it the problem because of hexadecimal number and decimal number?
here is the code for arduino uno
#include <DS3231.h>
#include <Wire.h>
#include<SPI.h>
const int temperature = A0;
int refresh = 30000;
DS3231 Clock;
bool Century=false;
bool h12;
bool PM;
float atm_temp;
byte year, month, date, DoW, hour, minute, second;
void setup()
{
Wire.begin(); // Start the I2C interface
pinMode(temperature,INPUT); // Pinsetup for temperature sensor
//settime(); // Set time in RTC {uploaded at beginning only once}
Serial.begin(115200); // Start the serial interface
Clock.setClockMode(false); // false for 24 hr and true for 12 hr
}
void loop()
{
timedisp();
tempdisp();
delay(refresh);
}
void tempdisp()
{
atm_temp = ((analogRead(temperature)/10240.0)*5000);
Serial.print(",");
Serial.println(atm_temp);
}
void timedisp()
{
Clock.getTime(year, month, date, DoW, hour, minute, second);
Serial.print(month, DEC);
Serial.print("/");
Serial.print(date, DEC);
Serial.print("/");
Serial.print("20");
Serial.print(year, DEC);
Serial.print(",");
Serial.print(hour, DEC);
Serial.print(":");
Serial.print(minute, DEC);
Serial.print(":");
Serial.print(second, DEC);
}
void settime()
{
Clock.setSecond(50);//Set the second
Clock.setMinute(16);//Set the minute
Clock.setHour(5); //Set the hour
Clock.setDoW(3); //Set the day of the week
Clock.setDate(4); //Set the date of the month
Clock.setMonth(8); //Set the month of the year
Clock.setYear(15); //Set the year (Last two digits of the year)
}
Related
I'm working on a flutter app, one of its features is to add your drug dose timings to get a reminder to take your drug. and I need to sort the timings to get the 'next_dose' to appear here :
https://drive.google.com/file/d/1j5KrRbDj0J28_FrMKy7dazk4m9dw202d/view?usp=sharing
this is an example of the list which I want to sort
[8:30 AM, 3:30 PM, 9:30 AM, 7:00 AM]
function I made to get the greater between 2 timings
int greater(String element,String element2){
var hour = element.toString().split(':')[0];
var hour2 = element2.toString().split(':')[0];
var minute = element.toString().split(':')[1].split(' ')[0];
var minute2 = element2.toString().split(':')[1].split(' ')[0];
var day = element.toString().split(':')[1].split(' ')[1];
var day2 = element2.toString().split(':')[1].split(' ')[1];
if(day == 'AM' && day2 == 'PM')
return -1;
else if(day2 == 'AM' && day == 'PM')
return 1;
else if(day == day2)
{
if(int.parse(hour) > int.parse(hour2)) return -1;
else if(int.parse(hour) < int.parse(hour2)) return 1;
else{
if(int.parse(minute) > int.parse(minute2))
return 1;
else
return -1;
}
}
here I tried to use the function to sort the list'Dose'
dose.sort((a,b)=>greater(a,b));
Instead of creating a sort callback with a lot of complicated logic, it'd be simpler if the callback parsed the time strings either into an int or into a DateTime object and compared those. For example:
/// Parses a time of the form 'hh:mm AM' or 'hh:mm PM' to a 24-hour
/// time represented as an int.
///
/// For example, parses '3:30 PM' as 1530.
int parseTime(String time) {
var components = time.split(RegExp('[: ]'));
if (components.length != 3) {
throw FormatException('Time not in the expected format: $time');
}
var hours = int.parse(components[0]);
var minutes = int.parse(components[1]);
var period = components[2].toUpperCase();
if (hours < 1 || hours > 12 || minutes < 0 || minutes > 59) {
throw FormatException('Time not in the expected format: $time');
}
if (hours == 12) {
hours = 0;
}
if (period == 'PM') {
hours += 12;
}
return hours * 100 + minutes;
}
void main() {
var list = ['8:30 AM', '3:30 PM', '9:30 AM', '7:00 AM'];
list.sort((a, b) => parseTime(a).compareTo(parseTime(b)));
print(list); // Prints: [7:00 AM, 8:30 AM, 9:30 AM, 3:30 PM]
}
Alternatively, you can use package:intl and DateFormat.parse to easily parse strings into DateTime objects.
Here we get the time slot by passing the start and end time duration.
List<String> createTimeSlot(
Duration startTime, Duration endTime, BuildContext context,
{Duration step = const Duration(minutes: 30)} // Gap between interval
) {
var timeSlot = <String>[];
var hourStartTime = startTime.inHours;
var minuteStartTime = startTime.inMinutes.remainder(60);
var hourEndTime = endTime.inHours;
var minuteEndTime = endTime.inMinutes.remainder(60);
do {
timeSlot.add(TimeOfDay(hour: hourStartTime, minute: minuteStartTime)
.format(context));
minuteStartTime += step.inMinutes;
while (minuteStartTime >= 60) {
minuteStartTime -= 60;
hourStartTime++;
}
} while (hourStartTime < hourEndTime ||
(hourStartTime == hourEndTime && minuteStartTime <= minuteEndTime));
debugPrint("Number of slot $timeSlot");
return timeSlot;
}
Function call
createTimeSlot(Duration(hours: 1, minutes: 30),
Duration(hours: 3, minutes: 30), context);
Output:
Number of slot [1:30 AM, 2:00 AM, 2:30 AM, 3:00 AM, 3:30 AM]
The seconds() method should call from main method and it should print the format of 00:00:00 January 1, 1901 GMT and it should return(calculate) number of seconds elapsed till user input time, I am new to the C++, I tried a lot but not able to make it happen
The code i tried:
// here i tried to start the day from the mentioned date and time
boost::posix_time::ptime timeObj = boost::posix_time::time_from_string("1901/01/01 00:00:00");
// Get current system time
boost::posix_time::ptime timeLocal = boost::posix_time::second_clock::local_time();
boost::posix_time::time_duration durObj = timeLocal.time_of_day();
std::cout << "Seconds : = " << timeLocal.time_of_day().seconds() << std::endl;
after this
I need to get a difference of seconds from 00:00:00 January 1, 1901 GMT to user input time.
in front of it should returns the format of 00:00:00 January 1, 1901 GMT.
I am doing this because I am customizing this boost library for our own product use.
Don't use time_of_day (because it gives the time-of-day).
Don't use seconds but total_seconds.
Use ptime arithmetic to get the difference. The rest was fine.
Live On Coliru
#include <boost/date_time/posix_time/posix_time.hpp>
size_t foo() {
boost::posix_time::ptime epoch { { 1901, 1, 1 } };
auto diff = boost::posix_time::second_clock::local_time() - epoch;
return diff.total_seconds();
}
int main() {
std::cout << foo() << "\n";
}
Which printed:
3710416481
Which should enable you to determine my average typing speed and my local timezone :)
I'm a beginner in Java, and I am receiving a format specifier error.
Just want to say that I am required to use the printf statement here.
Please see my code listed below:
package assignmentproject1;
/* CHANGE (FINAL) VAR NAMES, SCAN & VERIFY,
ORGANIZE AND PUT FORMULAS ON BOTTOM, ORGANIZE VAR # TOP, */
import java.util.*;
public class Project1
{
public static void main (String[] args)
{
Scanner stdin = new Scanner (System.in);
final double FEDTAX = 0.25, CALITAX = 0.09075, SS_MEDI_FICA = 0.0765,
UEIDI = 0.02, OVERTIMEHOURS;
double fedtax, ss_medi_fica, grossPay, rate, totalcost_to_Employer,
calitax, netPay, hours, ueidi, employerFICA;
boolean overtime = false;
//Inputs rate and hours, then calculates the gross pay.
System.out.print ("Enter hourly rate in dollars and cents --> ");
rate = stdin.nextDouble ();
while (rate > 0)
{
System.out.print ("Enter number of hours and tenths worked --> ");
hours = stdin.nextInt ();
System.out.println ();// LINE SPACER
System.out.println (" PAYROLL REPORT");
System.out.printf ("Rate:%38.2f \n",rate);
System.out.printf ("Hours:%37.2f \n",hours);
grossPay = rate * hours; //calculates gross pay.
fedtax = grossPay * FEDTAX; //calculates federal tax.
calitax = grossPay * CALITAX; //calculates state (CA) tax.
ss_medi_fica = grossPay * SS_MEDI_FICA; //employee pays for FICA.
ueidi = grossPay * UEIDI;
employerFICA = grossPay * SS_MEDI_FICA; //employer pays for FICA.
netPay = grossPay - (fedtax + CALITAX + SS_MEDI_FICA);
totalcost_to_Employer = grossPay + employerFICA
+ UEIDI;
//CHECKS CONDITION
System.out.println ();// LINE SPACER
if (hours > 40)
{
overtime = true;
grossPay = rate * 40 + (hours - 40) * (rate * 1.5);
System.out.printf ("Gross Pay: %32.2f \n", grossPay
+ "includes overtime");
}
else
{
grossPay = rate * hours;
System.out.printf ("Gross Pay: %32.2f \n", grossPay);
System.out.printf ("Federal Tax: %30.2f \n", fedtax);
System.out.printf ("State Tax: %32.2f \n", calitax);
System.out.printf ("FICA: %37.2f \n", ss_medi_fica);
System.out.printf ("Net Pay: %34.2f \n", netPay);
System.out.println ();
System.out.printf ("Employer's FICA contribution: %13.2f \n",
employerFICA);
System.out.printf ("Employer's UEI and DI contribution: %7.2f \n",
UEIDI);
System.out.printf ("Cost to Employer: %25.2f \n",
totalcost_to_Employer);
}
System.out.print ("Enter hourly rate in dollars and cents --> ");
rate = stdin.nextDouble ();
overtime = false;/*have to reset overtime,
so it doesn't apply to regular hours*/
}
}//end main
}//end class
I keep receiving errors when I input decimal values for both variables hours and rate.
I also receive errors when I input a number > 40 for the variable hours.
If I use integers only for hours OR payrate, then it seems to work fine.
I'm trying to decode a date encoded as a REG_BINARY in the Windows registry. Specifically this date:
SignaturesLastUpdated REG_BINARY 720CB9EBE8CBCE01
which should in 2013.
Any idea how to manually decode it? (i.e. without using any built-in C# or C++ library)
It's a FILETIME structure which is defined as:
Contains a 64-bit value representing the number of 100-nanosecond
intervals since January 1, 1601 (UTC).
The struct looks like this:
typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME;
Members
dwLowDateTime
The low-order part of the file time.
dwHighDateTime
The high-order part of the file time.
And here is how it can be converted to Unix time (in Go):
type Filetime struct {
LowDateTime uint32
HighDateTime uint32
}
// Nanoseconds returns Filetime ft in nanoseconds
// since Epoch (00:00:00 UTC, January 1, 1970).
func (ft *Filetime) Nanoseconds() int64 {
// 100-nanosecond intervals since January 1, 1601
nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime)
// change starting time to the Epoch (00:00:00 UTC, January 1, 1970)
nsec -= 116444736000000000
// convert into nanoseconds
nsec *= 100
return nsec
}
I had the following script working fine after changing from sp.getc to sp.gets.
require "rubygems"
require "serialport"
require "data_mapper"
#params for serial port
port_str = "/dev/ttyACM0"
baud_rate = 19200
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
loop do
sp_char = sp.gets
if sp_char.start_with?("Time")
printf("%s", sp_char)
end
end
I then reloaded the Arduino with the following (which I thought was what I had anyway?)
//SMS Send and Receive program
//Using Mega 2560 & Elecrow SIM900 GSM Shield
//4 July 2013
int count = 0;
int sendCount=0;
int n_sms,x,sms_start;
char data[300];
void setup()
{
Serial1.begin(19200); // the GPRS/GSM baud rate
Serial.begin(19200); // the USB baud rate
Serial1.println("AT\r");
Serial1.flush();
delay(1000);
Serial1.println("AT+CMGF=1\r");
Serial1.flush();
delay(1000);
Serial.println("Text Mode Selected");
Serial.flush();
//sendSMS();
}
void loop()
{
if(sendCount>720) //approx 60 minutes between sends
{
//sendSMS();
sendCount=0;
}
else
Serial1.print("AT+CMGR=1\r"); //Reads the first SMS
Serial1.flush();
for (x=0;x < 255;x++){
data[x]='\0';
}
x=0;
do{
while(Serial1.available()==0);
data[x]=Serial1.read();
x++;
if(data[x-1]==0x0D&&data[x-2]=='"'){
x=0;
}
}while(!(data[x-1]=='K'&&data[x-2]=='O'));
data[x-3]='\0'; //finish the string before the OK
Serial.println(data); //shows the message
Serial.flush();
Serial1.print("AT+CMGD=1,4\r");
Serial1.flush();
delay(5000);
sendCount++;
}
void sendSMS()
{
Serial1.println("AT+CMGS=\"+64xxxxxxxxxx\"\r");
//Replace this number with the target mobile number.
Serial1.flush();
delay(1000);
Serial1.println("SA\r"); //The text for the message
Serial1.flush();
delay(1000);
Serial1.write(0x1A); //Equivalent to sending Ctrl+Z
}
Now I get the following error :
serial_arduino.rb:16:in block in <main>': undefined methodstart_with?'for nil:NilClass (NoMethodError)
from serial_arduino.rb:14:in loop'
from serial_arduino.rb:14:in'
If I remove the start_with? method, then all is fine. Testing with irb shows method is OK
irb(main):003:0> 'AT'.start_with? 'Time'
=> false
irb(main):004:0> 'Time:0902'.start_with? 'Time'
=> true
Appears to be related to Arduino or my vitualised Debian machine. I have got it going after rebooting VM and powering off Arduino.