A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Set date and time in Linux Operating System using C++ program
Q:

Set date and time in Linux Operating System using C++ program

0

et date and time in Linux Operating System using C++ program

There is a command in Linux date which is used to get date and date - s can be used to set date and time in Linux Operating System.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

//function to set date and time
void setDateTime(int date, int month, int year,int hour, int min, int sec)
{
	//buffer to format command
	unsigned char buff[32]={0};
	//formatting command with the given parameters
	sprintf((char*)buff,(const char *)"date -s "%02d/%02d/%04d %02d:%02d:%02d"",month,date,year,hour,min,sec);
	//execute formatted command using system()
	system((const char *)buff);
}

//main funcion
int main()
{
	//calling function by passing date and time
	setDateTime(25,6 , 2017,10, 10,10);
	cout<<endl;
	return 0;
}

Output

Sun Jun 25 10:10:10 UTC 2017

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now