How to calculate timestamp difference in hours with MongoDB?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

752 Views

To calculate timestamp difference, use aggregate framework. Let us first create a collection with documents −> db.timestampDifferenceDemo.insertOne({    "MovieBeginningTime": new ISODate("2019-05-12 10:20:30"),    "MovieEndingTime":new ISODate("2019-05-12 12:30:20") }); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7ba1f6d78f205348bc644") } > db.timestampDifferenceDemo.insertOne({    "MovieBeginningTime": new ISODate("2019-05-12 04:00:00"),    "MovieEndingTime":new ISODate("2019-05-12 07:10:00") }); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd7ba3b6d78f205348bc645") }Following is the query to display all documents from a collection with the help of find() method −> db.timestampDifferenceDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd7ba1f6d78f205348bc644"),    "MovieBeginningTime" : ISODate("2019-05-12T10:20:30Z"),    "MovieEndingTime" : ISODate("2019-05-12T12:30:20Z") } {    "_id" : ... Read More

Elaborate the legal operands of the instance of operator in java?

Venkata Sai
Updated on 30-Jul-2019 22:30:26

82 Views

The instanceof operator in Java is used to find whether a reference is an instance of a Type i.e. class or an interface.Example Live Demopublic class InstanceOfExample {    public static void main(String args[]) {       String str = "hello";       boolean bool = str instanceof String;       System.out.println(bool);    } }OutputtrueLegal operands of the instanceof operatorThe following are the only legal operands of the instanceof operator −Left operand − It must be a reference representing an object.Right operand − It must be the name of Java class or, interface.Except these two if you use ... Read More

c16rtomb() function in C/C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

92 Views

In C++, we can use 16-bit character representations. The c16rtomb() function is used to convert 16-bit character representation to narrow multi-byte character representation. We can find this function inside the uchar.h header file.This function takes three parameters. These are −The string where multi-byte character will be stored16-bit character to convertThe pointer of type mbstate_t object. which is used to interpret multibyte string.This function returns number of bytes written to the character array, when it is successful, otherwise returns -1. Let us see an example to get better idea.Example Live Demo#include #include #include using namespace std; int main() { ... Read More

What is NaN in C++?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:26

708 Views

The NaN is the abbreviation of Not a Number. It indicates undefined or non-representable floating point elements. One example of NaN is square root of some negative number, or result of 0/0.Example#include #include using namespace std; int main() {    cout >> "Square root of -5: " >> sqrt(-5) >> endl; }OutputSquare root of -5: nan

Reverse a string in C/C++ using Client Server model

Smita Kapse
Updated on 30-Jul-2019 22:30:26

1K+ Views

Here we will see how we can create a system, where we will create one client, and a server, and the client can send one string to the server, and the server will reverse the string, and return back to the client.Here we will use the concept of socket programming. To make the client server connection, we have to create port. The port number is one arbitrary number that can be used by the socket. We have to use the same port for client and the server to establish the connection.To start the program, start the server program first −gcc ... Read More

How to schedule local notifications in Android?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

2K+ Views

This example demonstrate about How to schedule local notification in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 − Add the following code to res/menu/main_menu.xml.             Step 4 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.AlarmManager ; import android.app.Notification ; import android.app.NotificationManager ; import android.app.PendingIntent ; import android.content.Context ; import android.content.Intent ; import android.os.Bundle ; import android.os.SystemClock ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ... Read More

How to delete a table from MongoDB database?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

351 Views

Use drop() to delete a table. Following is the syntax −db.yourCollectionName.drop();Let us first create a collection with documents −> db.deleteTableDemo.insertOne({"Name":"Chris", "Age":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb705140b992277dae0e6") } > db.deleteTableDemo.insertOne({"Name":"Carol", "Age":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb70c140b992277dae0e7") } > db.deleteTableDemo.insertOne({"Name":"David", "Age":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb714140b992277dae0e8") }Following is the query to display all documents from a collection with the help of find() method −> db.deleteTableDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5ccfb705140b992277dae0e6"),    "Name" : "Chris",    "Age" : 23 } {    "_id" : ObjectId("5ccfb70c140b992277dae0e7"),   ... Read More

Customize the JOptionPane layout with updated color and image in Java

George John
Updated on 30-Jul-2019 22:30:26

1K+ Views

Customize the layout by changing the look and feel of the panel in which you added the component −ImageIcon icon = new ImageIcon(new URL("http −//www.tutorialspoint.com/images/C-PLUS.png")); JLabel label = new JLabel(icon); JPanel panel = new JPanel(new GridBagLayout()); panel.add(label); panel.setOpaque(true); panel.setBackground(Color.ORANGE);Above, we have added an image and even updated the background color of the panel.Now, set it for the text panel −JPanel textPanel = new JPanel(new GridLayout(10, 5)); textPanel.setBackground(Color.Magenta);The following is an example to customize the JOptionPane layout −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; public class SwingDemo { ... Read More

MySQL select to count values equal to 0 and greater than 0 from a column?

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

737 Views

For this, use the CASE statement. Let us first create a table −mysql> create table DemoTable    (    Number int    ); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.09 sec) mysql> insert ... Read More

What does immutable mean? Which Python types are mutable and which are not?

Sri
Sri
Updated on 30-Jul-2019 22:30:26

332 Views

In Python, there are two types of Objects.Mutable ObjectImmutable ObjectMutable: Mutable objects are modified, (i.e) objects are a changeable list, set, dict, etc are mutable.mutable objects are easy to change.Example 1list =["Tutorials ", "Point", "Pvt", "Ltd"] list[2]= 'Tutorix' listOutput['Tutorials ', 'Point', 'Tutorix', 'Ltd'] Example 2list=['Car', 'Bike', 'Scooty', 'Bus', 'Metro'] list[4]= 'Bicycle' listOutput['Car', 'Bike', 'Scooty', 'Bus', 'Bicycle'] Immutable: immutable objects are not modified (i.e) not changeable int, float, bool, str, tuple, Unicode, etc ... are immutable. immutable objects are expensive and difficult to change. a tuple is enclosed within the parenthesis tuples are immutable and can't be changed.Example 1tuple=('1', '2', 'Python', ... Read More

Advertisements